HTML and CSS Reference
This is the other big step you should take toward HTML5. New web pages should use CSS
to modify the appearance of web pages rather than HTML. Sticking with only those tags
and attributes in HTML5 and using CSS for everything else is a big step along that path.
HTML5 and XML
One of the biggest changes from XHTML 1.0 to HTML5 is that unlike XHTML 1.0,
HTML5 does not require documents to be valid XML. In XHTML 1.0, every tag had to
be closed, and every attribute was required to have a value to be valid XML documents.
HTML5 is like HTML 4.01—closing tags and attribute values are not strictly required.
That said, HTML5 documents can be formatted using valid XML—that's the approach
I've taken in this topic. Either approach is acceptable and browsers support both.
To indicate to the browser whether the page is valid XML, the Content-type header is
used. When a browser requests a web page, or an image, or any other resource from a
server, the response from the server includes a number of headers. These headers are
used by the server and browser to exchange information that isn't part of the web page.
The Content-type header is what the server uses to tell the browser what kind of
resource it's sending. The content types themselves come in two parts, separated by a
slash. The part before the slash describes the general type of the file, and the part after
the slash identifies the specific format of the file. So when a JPEG image is sent to the
browser, the content type is image/jpeg . Regular web pages use the content type
text/html . The content type enables the browser to figure out what to do with the
resource. Most of the time, it displays it in the browser, but if the content type is appli-
cation/pdf , it knows it needs to open a PDF reader and use it to display the file.
The HTML5 specification distinguishes between HTML5 that is valid XML and HTML5
that isn't using content types. The content type for vanilla HTML is text/html . If you
want the browser to treat the document as valid XML, you can use application/xml or
application/xhtml+xml . Right now, however, Microsoft Internet Explorer does not sup-
port those content types, so you should serve your HTML5 documents as text/html ,
whether they're valid XML.
Ultimately, it's up to you whether you choose to write XML-compliant HTML. Many
web designers are accustomed to XHTML 1.0 and write valid XML, and many tools do a
better job of catching errors in valid XML. On the other hand, if you're starting from
scratch, you can do what you like.