Skip to content
shawnbot edited this page Jun 25, 2012 · 14 revisions

This is a great way to start an HTML page:

<!DOCTYPE html>
<html>
  <head>
    <title>A meaningful title</title>
    <meta charset="utf-8">
  </head>
  <body>
  </body>
</html>

The HTML DOCTYPE

The <!DOCTYPE html> bit is probably the most important part. It's 2012, and there's literally no reason to use a DOCTYPE other than "html" at this point. XHTML is unnecessarily verbose, and HTML4 DTDs trigger quirks mode in many browsers. The "DTD-less" DOCTYPE embraced by HTML5 is the shortest and simplest way to ensure relatively consistent behavior among modern (and even not-so-modern) browsers.

A note about XHTML

XHTML is great if you want to be able to parse your document with an XML parser, but that's basically where the greatness ends. If you decide to use an XHTML DTD you'll also need an XML pragma before it, and browsers may refuse to render the page at all if it doesn't validate as XML (e.g., if you forget a closing slash on a self-closing element like <img> or <br>).

The UTF-8 Charset

If you've ever seen (or made) an HTML page that didn't display non-Latin characters properly, it was probably because it lacked the <meta charset="UTF-8"> tag. Many browsers (especially on Windows) default to non-unicode character sets, and will therefore fail to render unescaped unicode characters.

Next Steps

Clone this wiki locally