Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can <span> tags have any type of tags inside them?

Tags:

html

xhtml

Are tags such as <div>, <form>, <pre> etc.. allowed inside a <span>?

like image 926
Alex Avatar asked Apr 05 '11 00:04

Alex


People also ask

Can I put a tag in 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.

What can span contain?

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.

Can P tag be inside span?

This is not allowed according to the HTML5 specs.

Can you have nested span tags?

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.


1 Answers

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.

like image 111
Wayne Avatar answered Nov 05 '22 17:11

Wayne