(Also available in Spanish Traducción de “HTML 5 + XML = XHTML 5″ and Portuguese.)
I like the xhtml syntax. It’s how I learned. I’m used to lowercase code, quoted attributes and trailing slashes on elements like br and img. They make me feel nice and comfy, like a cup of Ovaltine and The Evil Dead on the telly.
But you might not. You might want SHOUTY UPPERCASE tags, no trailing slashes and attribute minimisation. And, in HTML 5, you can choose.
Thanks to the “pave the cowpaths” principle, it’s up to you. As you like it. What you will. Whatever you want, whatever you like.
But let no-one tell you that HTML 5 kills XML—meet XHTML 5.
XHTML 5 is the XML serialisation of HTML 5 and, as you’d imagine, it has all the stricter parsing rules that you’d expect (and are used to if, like me, you grew up with XHTML DOCTYPES). It must be served with an XML MIME type, such as application/xml or application/xhtml+xml (so no rendering in Internet Explorer for the moment) and will throw a wobbly at the slightest well-formedness violation. (See Serving XHTML with the Right MIME Type for more information.)
Usual XML rules apply: no document.writes allowed, no DOCTYPE required, some syntax and script differences to trip up the unwary and you can use namespaces.
The main differences are summarised on the official WHATWG wiki Differences Between HTML and XHTML. It’s also possible to write polyglot documents that can be processed as either by browsers, depending on the MIME type used.
Magne emailed the Doctor to ask “Is it OK to use HTML5 tags in a page with the XHTML 1.1 doctype? Which one should I use, as in, which one is the recommendation now?”
If you want to use the new features, you need to use HTML 5 DOCTYPE or XHTML 5. Given that Internet Explorer cannot process XML, for pragmatic reasons the Doctor advises HTML 5.
48 Responses to “ HTML 5 + XML = XHTML 5 ”
Comment by Kroc Camen at
application/xhtml+xml? Yes, you can serve as pure XML, but xhtml+xml may be marginally more relevant.
Secondly, you’ll need XHTML5 in order to support Firefox 2 / Camino, so I would recommend including a link to the document on this site that covers that.
Comment by kl at
You can use lowercase and quoted attributes in HTML too.
Comment by Bruce Lawson at
Kroc – well, sending html5 (in its html5 form) as xhtml just for a gecko parsing bug is not the same thing as “real” xhtml, so I’m loathe to confuse those two issues.
Re application/xml vs application/xhtml+xml – you’re right. It was a brain fart on a hot day and I’ve corrected the article; thanks.
Comment by mynthon at
discussion about that:
http://crisp.tweakblogs.net/blog/321/html5-why-not-use-xml-syntax.html
Comment by Horus Kol » XHTML2 Being Closed in Favour of X/HTML5 at
[...] W3C announced a few days ago that the XHTML2 working group will likely be closed down by the end of the year, and focus will be shifted to the development and polishing of the HTML5 standard (which also offers an XML flavour). [...]
Comment by Ben Ward at
Nice summary for those who love the XML. One additional detail I’d point out, is the reverse: Which is that the HTML version of the HTML5 syntax also makes XML-like self-closing elements valid for elements that are expected to be self-closing, e.g. you may choose to write
<link />. As such, XHTML syntax as we know it is now HTML, too.This, for those who want to continue writing XHTML in the HTML5 world is a bridge: They can write XHTML and serve it as HTML just as they do now, but it will be valid.
At some point, if IE ever plays ball, those people can swap over to the correct mime type and start using namespaces and so on.
Comment by Bruce Lawson’s personal site : Goodbye XHTML 2 at
[...] interested in HTML 5, I draw your attention to an article that I presciently wrote yesterday on XHTML 5, for those who worry unnecessarily that XML has been [...]
Comment by Bruce Lawson at
@Ben – excellent points; thanks for making them.
Comment by IE6 falls; XHTML2 cancelled. | Wisdump at
[...] The good thing about XTHML was that it enforced well-formed markup, with strict provisions for lowercase code, quoted attributes, and trailing slashes for empty elements. Thankfully HTML5 this coding convention too, and can be served as a serialized XML document dubbed XHTML5. [...]
Comment by Dari at
Wait a second. Actually how do browsers know if document is xhtml 1.0 strict or xhtml 5? According to docs http://www.whatwg.org/specs/web-apps/current-work “XML documents may contain a DOCTYPE if desired, but this is not required to conform to this specification.” + note below. Because both documents share same namespace and doctype could be just thrown away all xhtml 1.x documents are probably xhtml 5 right now.
Comment by andy at
I thought that WHATWG criticised W3C for XHTML (XML usage in HTML).
Apart from xml mime type that is not supported by IE, there are more disavantages — xml parser will stop when welll-formed error occurs, browser must wait until the code for a page is fully loaded.
So, the only advatage of XHTML5 is cleaner, strict code?
Thanks
Comment by Kroc Camen at
@andy – Firefox 3.0 and above don’t have to wait for the full XML to render the page.
Comment by Daniel Palmério at
The name must be XHTML2, not?
Comment by Bruce Lawson at
Daniel, no – XHTML 2 was a competing specification that last week was terminated by the w3c http://www.brucelawson.co.uk/2009/goodbye-xhtml-2/
XHTML 5 is the XML version of HTML 5, so the numbering is the same to link with that and avoid confusion with the dead spec.
Comment by XHTML2 subsumed under HTML5 « Freddy at
[...] XHTML5 – “But let no-one tell you that HTML 5 kills XML—meet XHTML 5.” - Good, good coding standards will still have to be used. [...]
Comment by Torrance at
(Merde. Let me escape all my tags. Feel free to delete the prior post.)
Perhaps this should be in another article, but coming from writing XHTML 1.1, I’m having trouble understanding which tags no longer need to be closed, and which seem to be able to be omitted altogether.
I understand that self-closing tags no longer need the forward slash at the end, but I’ve seen someone suggest that <li> doesn’t need its respective closing tag, and nor even does <p>. Surely this is not true? And why is <body> no longer strictly necessary? What else has become optional?
I think for my own sanity, I’ll be sticking to XHTML syntax even in HTML 5. Makes me feel a lot cleaner knowing everything is neatly closed.
Comment by oli at
@Dari—XHTML5 and HTML5 are differentiated solely by mime type. That means unless you specifically use the application/XHTML+XML mime type it’s HTML5, and as mentioned in the article you’re probably not going to do that because IE would barf (what a surprise).
@andy—the main advantage of using XHTML (ie based on XML) would probably be the easy inclusion of other XML-based things like SVG, XForms and MathML. Another benefit of using XHTML1 has traditionally been stricter validation which is a big help to authors. Hopefully this will migrate to HTML5 browsers in the form of a strict mode or something. As the article says though, if you have *any* IE users then XHTML5 is probably more time than it’s worth.
Comment by andy at
@oli — yep, but if you have to use text/html in these days, you can’t put another xml application to the code. So only way how to do that is embed it via object element. Besides svg, I don’t know any other xml apps which is usable because of its poor support — MathML, CML, …
I use xhtml just because I like pure well-formed code, but any other objective reason I can’t say.
And as I mentioned, I can’t put up with unaccessible browsers’ xml parsers.
Comment by Dari at
@oli – I said about the difference between xhtml1 and 5, not html->xhtml. Because I don’t see any. Technically document with xhtml 1.0 doctype should be xhtml 1.0 but how do UA know that?
Comment by Traducción de “HTML 5 + XML = XHTML 5″ « HTML 5, información útil en español at
[...] muy amablemente me dió el permiso para publicar una traducción de su artículo llamado “HTML5 + XML = XHTML 5” publicado el 2 de julio de 2009 en HTML5 Doctor. Así que ¡muchas gracias [...]
Comment by Magne Andersson at
Is there currently a validator that will validate HTML5 as XHTML (any version) Strict, as clean code was the only advantage I could make use of with XHTML, and I still want to be able to do?
Comment by rovas at
@Magne: You could try this one:
http://validator.nu/
There are a lot of options.
Cheers!
Comment by Shopping Mall » Misunderstanding Markup: XHTML 2/HTML 5 Comic Strip at
[...] Bruce’s Quote [...]
Comment by Advertisers Blog » Misunderstanding Markup: XHTML 2/HTML 5 Comic Strip at
[...] Bruce’s Quote [...]
Comment by Misunderstanding HTML markup | Manakor Coding Map™ at
[...] right; HTML 5 allows you to use whichever syntax you are most comfortable with. Doctor Bruce has the diagnosis: I like the XHTML syntax. It’s how I learned. I’m used to lowercase code, quoted attributes and [...]
Comment by Misunderstanding Markup: XHTML 2/HTML 5 Comic Strip | Search Engine Optimisation at
[...] Bruce’s Quote [...]
Comment by 70 Must-Have CSS3 and HTML5 Tutorials and Resources | trackteq.com at
[...] HTML 5 + XML = XHTML 5 – An general outlook of how HTML 5 will correlate with XML. [...]
Comment by 70 Must-Have CSS3 and HTML5 Tutorials and Resources - Iconlandia at
[...] HTML 5 + XML = XHTML 5 – An overview of how HTML 5 will interact with XML. [...]
Comment by AMB Album » 70 Must-Have CSS3 and HTML5 Tutorials and Resources at
[...] HTML 5 + XML = XHTML 5 – An overview of how HTML 5 will interact with XML. [...]
Comment by 70 Must-Have CSS3 and HTML5 Tutorials and Resources @ Kent's Blog at
[...] HTML 5 + XML = XHTML 5 – An overview of how HTML 5 will interact with XML. [...]
Comment by 70+ 必备的 CSS3 和 HTML5 教程资源 « 脚本 at
[...] HTML 5 + XML = XHTML 5 - 概览 HTML5 怎样和 XML 实现交互。 [...]
Comment by Adept > 70 Must-Have CSS3 and HTML5 Tutorials and Resources at
[...] HTML 5 + XML = XHTML 5 – An overview of how HTML 5 will interact with XML. [...]
Comment by 70 CSS3 and HTML 5 tutorials and resources | Netfire.us - Design tutorials, articles, resources, and creative inspiration. at
[...] HTML 5 + XML = XHTML 5 [...]
Comment by 70 Must-Have CSS3 and HTML5 Tutorials and Resources | huibit05.com at
[...] HTML 5 + XML = XHTML 5 – An overview of how HTML 5 will interact with XML. [...]
Comment by CSS3 Gallery, Showcase & Inspiration. Showcasing the best CSS3 Web Design on the Internet | 70 CSS3 & HTML5 Tutorials | CSS 3 Gallery at
[...] HTML 5 + XML = XHTML 5 – An overview of how HTML 5 will interact with XML. [...]
Comment by HTML 5 - The Revolution will not be Televised | The Worm Hole at
[...] arguments and that XHTML was dead. The truth of course was slightly more complicated as HTML 5 can be reasonably presented as XHTML. Either way we now seem to have one standard to unite behind which brings us closer to [...]
Comment by CSS3 y HTML5: Tutoriales y recursos para el nuevo diseño web | Recursos para desarrollo y diseño web - AlmacenPlantillasWeb Blog at
[...] HTML 5 + XML = XHTML 5 – Introducción a la interacción de HTML 5 y XML. [...]
Comment by Html/xml/xhtml - html.de Forum - HTML f at
[...] [...]
Comment by Yun4 - XML On HTML 5 at
[...] Bruce Lawson nicely summarizes the whole deal on using XML on HTML, writing your markup in a XML format and serving them as HTMLis still valid. This also [...]
Comment by ピエールランリ・ラヴィン at
Thanks for the article. Anyway, what exactly is the doctype for xhtml 5 please ? I didn’t find an real answer on the web. Can i use this one for example ?
Thanks
Comment by ピエールランリ・ラヴィン at
Arg I meant:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
Comment by Alohci at
The point about the character sequence <!DOCTYPE html> is that it is the shortest set of characters that will cause browsers to use standards mode, when the page is served as text/html. It’s not so much a doctype as an incantation. A page is only XHTML5 if it is served with a xml mime type (e.g. application/xhtml+xml), and in such cases browser use standards mode anyway. So while you can include <!DOCTYPE html> if you wish, it is entirely optional.
Comment by bruce at
“It’s not so much a doctype as an incantation”
Perfectly put, Alohci!
Comment by e-sushi at
Jumping in a bit late… people have to understand that HTML5 is made to “accept older doctypes and handle them”. In other words, the HTML5 doctype allows you to use almost anything you want, as long as it confirms to previous standards. Translated this means that you can take your XHTML1.1 document, slap the doctype line to a minimal and push it up to the server. HTML5 will be read.
About the “header” for the MIME type, I can not see why you would serve the document with anything else but “text/html”, because in fact, you are serving just that! Using HTML5 you can write xml or non-xml syntax, as long as the “html,head,body”-structure is kept. Geez, I know it is hard to accept that you don’t get a resticting doctype next, but hey… that’s what it’s all about; making HTML5 the doctype “to rule them all” by being open for old an even some new stuff. See, HTML5 is not about canvas and co, HTML5 is about wrapping up ALL previous doctypes and adding goodies like canvas etc. to it.
My 2 cents… get rich using them!
Comment by 70+ 必备的 CSS3 和 HTML5 教程资源 | 芒果 at
[...] HTML 5 + XML = XHTML 5 - 概览 HTML5 怎样和 XML 实现交互。 [...]
Comment by 70+ 必备的 CSS3 和 HTML5 教程资源 « SomeDay I'll Fly | Gabriel's blog at
[...] HTML 5 + XML = XHTML 5 - 概览 HTML5 怎样和 XML 实现交互。 [...]
Comment by HTML 5 oder XHTML 2 at
[...] Everything you know about XHTML is wrong – Goodbye XHTML 2 – HTML 5 + XML = XHTML 5 – 2022, or when will HTML 5 be ready? XHTML 1.0 ist nicht (viel) mehr als HTML mit XML-kompatiblen [...]
Comment by The i, b, em, & strong elements | HTML Guide at
[...] HTML 5 + XML = XHTML 5 [...]