Slack 'n' Hash

HTML Tutorial

The Head

So far, so good. We've got lots of tags to put in the body of the web page. Plenty of options for document structure there. But what about the head? I said earlier that that section is set aside for information about the web page, and so it is. However, the <title> tag is but the tip of the iceberg.

Document Type

At some point you may wish to run your code through a validator. If so, good for you! Well-structured code is valid, well-formed code. That doesn't necessarily mean all valid code is well-structured, but it's a good start. There are certain things you need to do right at the beginning of your document or your code simply will not validate.

You have to include a document type declaration. XHTML has three kinds of doctype declaration, and it's up to you which one you wish to use. In all cases, put the declaration right at the top of the document, before the opening <html> tag.

XHTML Strict DTD

This is probably the best declaration to use. It's the strictest possible definition, in which no presentational elements of XHTML are used: it's all about the structure. All presentation is left to CSS.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

XHTML Transitional DTD

If you feel you can't do without those presentational tags, or can't commit to using the strict definition for some reason, Transitional is a safer option.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

XHTML Frameset DTD

Thankfully, frames aren't as widespread as they used to be, but if you feel your website absolutely has to have frames, use this declaration:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

Back to the <html> tag

Now we're feeling a bit more confident, we can move onto the next bit of the head section that is concerned with validation. XHTML is part of a movement to base HTML on XML rather than its original forbear, the more complex SGML. What does this mean? To you and me? Not a lot at present; but it means in order for an XHTML document to validate, an attribute has to be set on the opening <html> tag.

    <html xmlns="http://www.w3.org/1999/xhtml">

Simple as that.


Last modified: 26/11/08. All material ©2003-8 its creators.

Customise the Sidebar