Is there such a thing as a valid HTML5 snippet?

I obviously cannot determine if the HTML fragment is valid without knowing what the rest of the document looks like (at least I need a doctype type to find out what rules I check). But given the following HTML5 snippet:

<article><header></article>My header</header><p>My text</p></article>

I can definitely determine that it is invalid without seeing the rest of the document. So, is there such a thing as “conditionally valid” HTML, or “really if it fits a specific place in a valid document”?

Is there more to it than the following pseudo code?

def is_valid_fragment(fragment):
 tmp = "<!doctype html><html><head><title></title></head><body>" + fragment + "</body></html>"
 return my_HTML5_validator.is_valid_html5_document(tmp)
+5
source share
2 answers

, , , XML- well-formed, . , XHTML5 . (, <img/><img/>), - -, , .

HTML5 - SGML, <hr> .., doctype. , <div><hr></div> , <div><tr></div> . DOM, , , , , HTML, . , , XML, .

validity, , - XML. :

XML , , .

DTD , .. , .

, HTML. , . , (, ) , , .

+3

, .

-3

All Articles