Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it valid to nest <html> inside <html>?

Is this valid HTML?

<!DOCTYPE html>
<html>
    <head/>
    <body>
        <p>Hello, World</p>
        <html>
            <head/>
            <body>
                <p>Hello, World 2: Revenge of the Pointer</p>
            </body>
        </html>
        <html>
            <head/>
            <body>
                <p>Hello, World 3: GOTO null</p>
            </body>
        </html>
    </body>
</html>

According to the HTML5 specs, the <html> element can be used:

  • As the root element of a document.
  • Wherever a subdocument fragment is allowed in a compound document.

It's the second part that I'm confused about. Does this mean that <html> is a "document" and any nested <html> is a "subdocument fragment"? How can I tell if this is "allowed"?

like image 283
Scribblemacher Avatar asked May 04 '26 05:05

Scribblemacher


2 Answers

As said by Guffa

A compound document is a document in itself and you can't use html to make a sub-document.

But a html may contain a iframe which is a sub-document and has html tag. enter image description here

like image 106
Golden_flash Avatar answered May 06 '26 22:05

Golden_flash


No, that is not valid.

A compound document has a subdocument fragment declared inside it, which is a complete document in itself. You can't just use another html tag to make a compound document.

like image 26
Guffa Avatar answered May 06 '26 23:05

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!