HTML5 can also be written using a stricter, XML-like syntax. You may remember from Chapter 1 that XHTML 1.0 was a reformulation of HTML 4 as an XML 1.0 application. That isnt quite true of what is sometimes called XHTML5″. XHTML5 is best understood as HTML5 thats written and parsed using the syntax rules of XML and served with a Content-type: application/xml+xhtml response header.

The following rules apply to XHTML5″:

All elements must have a start tag.
Non-void elements with a start tag must have an end tag.
Any element may be self-closed using />.
Tags and attributes are case sensitive, typically lowercase.
Attribute values must be enclosed in quotes.
Empty attributes are forbidden (checked must instead be checked="checked" or checked="true").
Special characters must be escaped using character entities.

Our html start tag also needs an xmlns (XML name space) attribute. If we rewrite our document from above to use XML syntax, it would look like the example below.

<html xmlns="">
      <meta charset="utf-8" />
        <img src="flower.jpg" alt="Flower" />
        Isn't this a lovely flower?
      <script src="foo.js" />
Here weve added the XML name space with the xmlns attribute, to let the browser know that were using the stricter syntax. Weve also self-closed the tags for our empty or void elements, meta and img. According to the rules of XML and XHTML, all elements must be closed either with an end tag or by self-closing with a space, slash, and a right-pointing angle bracket (/>).

In this example, we have also self-closed our script tag. We could also have used a normal tag, as weve done with our other elements. The script element is a little bit of an oddball. You can embed scripting within your documents by placing it between script start and end tags. When you do this, you must include an end tag.

However, you can also link to an external script file using a script tag and the src attribute. If you do so, and serve your pages as text/html, you must use a closing tag. If you serve your pages as application/xml+xhtml, you may also use the self-closing syntax.

Dont forget: in order for the browser to parse this document according to XML/XHTML rules, our document must be sent from the server with a Content-type: application/xml+xhtml response header. In fact, including this header will trigger XHTML5 parsing in conforming browsers even if the DOCTYPE is missing.

As you may have realized, XML parsing rules are more persnickety. Its much easier to use the text/html MIME type and its looser HTML syntax.