I have a span with an inculded p, like this:
<span>
<p>this is the p</p>
</span>
This is not allowed according to the HTML5 specs. Now, my HTML is more complex than the above and I need something similar to a p which I can use instead. Which tag could I use or which element can I change using css so it behaves like a p?
This is not allowed according to the HTML5 specs.
The span element is an inline element, which should contain only other inline elements and no block elements. From the spec: Generally, block-level elements may contain inline elements and other block-level elements.
In HTML 4, the DIV element cannot be inside another block-level element, like a P element. However, in HTML5 the DIV element can be found inside and can contain other flow content elements, like P and DIV.
How to style text with the span tag. If you want to makes some particular text or any other content different from the rest, you can wrap it in a span tag, give it a class attribute, then select it with the attribute value for styling.
p
has a meaning.
If your content matches p
’s definition, you should use p
. Then you should use a div
instead of a span
(unless there is no other suitable candidate):
<div>
<p>…</p>
</div>
If your content doesn’t match p
’s definition, you shouldn’t use p
. Then you could use span
instead of p
(if there is no other suitable candidate):
<span>
<span>…</span>
</span>
span
and div
don’t have meanings. So you only have to consider where they are placed syntactically (block vs. inline). You can swap them without losing/changing any semantics:
<div>
<span>…</span>
</div>
<div>
<div>…</div>
</div>
Note that all this doesn’t have anything to do with how these elements are styled. You can style a block-level element with CSS so that it appears as inline and vice-versa: display:inline;
resp. display:block;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With