Are nested span tags OK in XHTML?

HtmlXhtml

Html Problem Overview


Will this validate in XHTML?

<span>hello<span>world</span></span>

Html Solutions


Solution 1 - Html

Yes it will. You can help yourself by using the w3's validator direct input option:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
          <title>Title</title>
        </head>

        <body>
           <p>
               <span>Test<span>Nest span</span></span>
           </p>
        </body>
      </html>

Solution 2 - Html

Absolutely.

Here's the definition from an XHTML-strict DOCTYPE for a span element.

<!ELEMENT span %Inline;> <!-- generic language/style container -->
<!ATTLIST span
  %attrs;
  >

The "%Inline" part tells me that it can have child nodes from the "% Inline;" entities element list.

The span element is included in the list of elements classed as "% Inline", that combined with span allowing "%Inline" child elements tells me that span is a valid child of span.

Solution 3 - Html

SPAN can contain only inline elements, such as SPAN etc.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrickView Question on Stackoverflow
Solution 1 - HtmlRichardODView Answer on Stackoverflow
Solution 2 - HtmljoebertView Answer on Stackoverflow
Solution 3 - HtmldusoftView Answer on Stackoverflow