Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a span tag outside a p?

Tags:

html

tags

I was placing some icon fonts inside a link and then i asked myself: is semantically correct to use a span tag outside a p one?

In example

<a href="http://fb.com">
    <span class="my-icon-font">link</span>
</a>
like image 600
Luke Avatar asked Mar 22 '23 17:03

Luke


2 Answers

From a semantic perspective, a span really doesn't mean much. It's just a marker for some inline content.

From a technical perspective, a span can go anywhere that you have an inline display context, which basically means anywhere at all (since HTML allows you to have inline elements in the same context as block elements).

It certainly isn't limited to being inside a p tag. It can go pretty much anywhere.

like image 136
Spudley Avatar answered Apr 07 '23 15:04

Spudley


The short answer is NO

You can read these two section

span element

Contexts in which this element can be used: Where phrasing content is expected.

p element

Contexts in which this element can be used: Where flow content is expected.

Content model: Phrasing content.

A span just allows phrasing content element inside it while a p is an flow content element. However, a p can contains a span.

like image 36
Hieu Le Avatar answered Apr 07 '23 16:04

Hieu Le