Search code examples
htmlxhtmlvalidationw3c

Is there an XHTML 5 validator?


Is there a validator specifically for XHTML 5, i.e. the XML serialization of HTML 5? The W3C validator supports the document types:

  • HTML 5 (experimental): which treats as valid various features that are not allowed in XML, such as implicitly closed <br> tags.
  • several XHTML 1.0 and XHTML 1.1 doctypes, which don't recognize the new tags in HTML 5.

Solution

  • The W3C validator for HTML 5 in fact does detect and validate XHTML 5:

    • When validating by URI, it uses the content-type provided by the server (XHTML if it specifies application/xhtml+xml).
    • When validating by file upload or direct input, it guesses based on whether an xmlns attribute is present in the file. That is,

    This is identified as XHTML (and is therefore correctly marked invalid):

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>test</title></head>
    <body><br></body></html>
    

    This is identified as HTML (and is therefore correctly marked valid):

    <!DOCTYPE html><html>
    <head><title>test</title></head>
    <body><br></body></html>
    

    Edit: Apparently they're removing this auto-identification. See this bug.