Doing HTML Right

We've noted that HTML is very forgiving

A look at a decent template

I have a template file that I use for this website that includes all the basics. When I make a new page, I just copy the template and add the content. Here is what the template looks like:

<!DOCTYPE html>
<html lang=en>
    <head>
        <title>Your page title</title>
        <meta charset="utf-8"/>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel='stylesheet' type='text/css' href='style.css'>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel='alternate' type='application/rss+xml' title='Site Title RSS' href='/rss.xml'>
    </head>
<body>
    <header><h1>Your page title</h1></header>

    <nav></nav>

    <main>

    Put all your page content here in the <main> tag.

    </main>

    <footer></footer>
</body>
</html>

Explanation of All These Important Things

The Importance

If you're new to this world, you might be wondering why you should use body and main and nav and header and all this seemingly confusing stuff! (Especially when even bad HTML displays!)

Not only do many devices, especially mobile ones, specifically use these tags for their features, but when using CSS, we can also style each of these elements the way you want them to appear without changing the HTML on all your pages.

With CSS, we can say that we might want the whole body to have a image background, but main should be floating over it semi-transparent. We can tell nav to float off on the left or right and we can change footer and nav settings just by tweaking the CSS.

Speaking of which, we've been talking up CSS for a while, so now it's time to learn it!

Next: Styling with CSS