An XHTML 5 Template
Here is a basic XHTML5 template that you can use as a starting point for creating all your web pages if you decide to use XHTML5.
<?xml version="1.0" encoding="UTF-8"?>
<title>An XHTML 5 Template</title>
<link rel="stylesheet" href="css/main.css"/>
Let's now take a look at the template and consider why certain things are or are not included.
- Not shown but necessary is an HTTP header setting the MIME type to "application/xhtml+xml". How you add this depends on which server side language or web server you are using. It is this which determines whether a web page is HTML or XHTML.
- No doctype is required. Versions of (X)HTML between 2 and 4 were defined using SGML and therefore could have an optional SGML doctype. There is no SGML doctype for either HTML5 or XHTML5. HTML5 added a stub doctype as an HTML tag because browsers use it to determine whether the browser should display the page in standards or quirks mode. XHTML doesn't have a quirks mode and so no tag is needed to force standards mode.
- The XML tag can be omitted provided that the default encoding is set to UTF-8. Note that no metatag specifying a charset is needed as XHTML ignores that tag as the charset has already been determined before the <html> tag is read.
- The namespace for XHTML needs to be specified on the html tag. If other markup languages (eg. svg) are also included in the page then the namespace for those languages will also need to be defined on the tag wrapping their content.
- The type can be omitted from the link tag because the default for .css files when it is omitted is "text/css" which is in fact the correct type for the CSS we are using the link tag to attach.
- The tags I have included inside the body are the main ones that I'd expect each page to need. Whether the nav comes after the main content or is included in the header depends on how you want the page laid out.
- Note that where I have included self-closing tags there is no space in front of the closing slash. That space was only required when serving pages as HTML to Netscape 4 and has not been necessary even when you use XHTML syntax in HTML in any more recent browsers.
This article written by Stephen Chapman, Felgall Pty Ltd.