我正在学习 HTML 5 并且有一个问题:可以在 XHTML 1.1 文档中使用 HTML 5 吗?如果是,那么有人可以举个例子吗?
2 回答
Do not confuse XHTML and HTML.
XHTML is HTML ruled to be a valid XML document. Actually the XHTML 1.1 standard does not apply to HTML 5 but to HTML 4.01.
What does it mean? You can pick a valid XHTML 1.1 document and it'll be a valid HTML 5 document but the counter-part is not always true. For example:
<button disabled></button>
It's valid HTML code (it doesn't matter which version) but it's not a valid XML statement (then it's not a valid XHTML document) because of the empty attribute. World is full of these examples (just Google), HTML is very relaxed about syntax (and HTML 5 didn't change this direction) and there are some other differences too (here, for an example). Moreover the HTML 5 standard introduced new tags that aren't part of XHTML 1.1 standard so a fully featured HTML 5 document (despite the syntax) won't be a valid XHTML 1.1 document.
References
Here a short list of good reference about this topic, selected from SO answers:
- HTML/XHTML and MIME type: a short answer about content type and markup syntax.
- All-in-one about HTML and XHTML: a long list of QA that covers different aspects of HTML/XHTML compatibility.
- What to use: a question about what is better to use between HTML and XHTML (of course the answer is it depends but the answer itself is good).
- XHTML/HTML for mobiles: some nice tips about HTML5/XHTML with Apple's devices.
理论上不会,因为xhtml和html的标准集是不同的。但是,它是否工作完全取决于您使用的浏览器,大多数现代浏览器将显示另一组标签以及您定义的标准。