Are tags such as <div>
, <form>
, <pre>
etc.. allowed inside a <span>
?
The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.
Only inline elements may be contained within inline elements. span is an inline element. So, tags like a , img , sup , etc. can go within a span, but block level elements like div and p cannot.
This is not allowed according to the HTML5 specs.
The HTML span TagYou shouldn't nest span unless you thoroughly know what you're doing – but you can put multiple span tags within a block-level element.
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. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.
The generic block-level grouping element is the div
. The generic inline-level grouping element is the span
.
Again, from the spec:
The DIV and SPAN elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content.
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