[ACCEPTED]-Is HTML5 valid XML?-xhtml

Accepted answer
Score: 44

No. Counter-examples:

These are valid HTML5 but invalid XHTML5:

  1. Some 11 closing tags can be omitted:


    See: P-end-tag (</p>) is not needed in HTML

  2. script escape 10 magic:


    See: What is CDATA in HTML?

  3. Attributes without values (boolean 9 attributes):

    <input type="text" disabled />

    See: Correct value for disabled attribute

  4. Attributes without quotes, e.g.:

    <div data-a=b></div>

    See: In XHTML 1.0 Strict do attribute values need to be surrounded with quotes?

  5. Implicit 8 open elements and multiple top level elements.

    Some 7 HTML elements are created implicitly. E.g. html. This 6 allows the HTML to have "multiple top 5 level elements":

    <!doctype html><title>a</title><p>a</p>

    See: Is it necessary to write HEAD, BODY and HTML tags?

Valid XHTML that 4 is invalid HTML:

  1. CDATA constructs with invalid 3 tags inside

  2. ENTITY and other exclamation mark constructs, which 2 allow for billion laughs: How does the billion laughs XML DoS attack work?

Valid HTML and 1 XHTML but with different meanings:

  1. HTML has hundreds of named character references (e.g. &pound;, &copy;), XML has only 5 (quot, amp, apos, lt, gt).
Score: 11

There is an XML serialization of it, called 6 XHTML5. Basically, you're free to use either 5 HTML5 (HTML serialization) or XHTML5 (XML 4 serialization). The draft spec says HTML5 3 "is the format suggested for most authors," mainly 2 for the same reasons people recommend text/html for 1 XHTML 1.1.

Score: 11

You can markup your page as valid HTML5 9 and XHTML5: http://www.w3.org/TR/html-polyglot/

Polyglot markup that meets a well 8 defined set of constraints is interpreted 7 as compatible, regardless of whether they 6 are processed as HTML or as XHTML, per the 5 HTML5 specification.

The basic document could 4 look like:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

Of course you'd have to follow 3 some additional rules (like not to use the 2 noscript element, for example), outlined in the 1 linked working draft.

Score: 3

HTML5 can be written with or without self-closing 8 slashes; it is meant to be backwards-compatible 7 with both HTML 4.01 and XHTML 1.0 6 code, so that it is easy to convert code 5 into valid HTML5. There is an XML serialization 4 called XHTML5, but for backwards-compatibility 3 purposes with IE browsers, it is not recommended 2 to be used. So technically, HTML5 is not considered 1 to be well-formed XML.

Score: 2

Under no condition should you expect any 9 html document (regardless of version) to 8 be "well-formed xml"

html != xml.

It is a different 7 spec with different suggestions (I'm purposely 6 avoiding the word "rules" here) on how it 5 should be interpreted.

The HTML 5 spec 4 has enough "do it this way, but it's okay 3 if you don't" wiggle statements that it's 2 a wonder that any of the browsers show the 1 same thing at all.

More Related questions