[ACCEPTED]-Is HTML5 valid XML?-xhtml
No. Counter-examples:
These are valid HTML5 but invalid XHTML5:
Some 11 closing tags can be omitted:
<p>First <p>Second
script
escape 10 magic:<script><a></script>
Attributes without values (boolean 9 attributes):
<input type="text" disabled />
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?
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>
Valid XHTML that 4 is invalid HTML:
CDATA
constructs with invalid 3 tags insideENTITY
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:
- HTML has hundreds of named character references (e.g.
£
,©
), XML has only 5 (quot
,amp
,apos
,lt
,gt
).
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.
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">
<head>
<title></title>
</head>
<body>
</body>
</html>
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.
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.
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
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.