153
votes

Will this validate in XHTML?

<span>hello<span>world</span></span>
3
I wonder how this question managed to collect hundreds of upvotes over the years.Mr Lister
@MrLister I guess because I have just googled the question and this article showed up ... :)Andrew Truckle

3 Answers

145
votes

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>
88
votes

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.

29
votes

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