Sunday, February 25, 2007

In the beginning there was DOCTYPE

Alright, in the beginning there wasn't DOCTYPE, it didn't come along until about the time XHTML was released; however, if you want to do the Web 2.0 thing right, it helps to start on a solid base.

My goal here is to get a brand-new HTML document up and running as a good base for designing a Web 2.0 application. Today, we'll look at the parts of a document that the typical user doesn't actually see, but play a huge role in how a user finds your site and how it's actually rendered on their screen.

First things first; make your DOCTYPE the first line of the file. That's right, line number one, no XML definition, no spaces, no server-side code, the first line of the file. This ensures that you don't end up in quirks mode accidentally. Now, as far as DOCTYPE's go, I really only see two options, HTML 4.01 Strict and XHTML 1.0 Strict. There are theoretically valid arguments for not using XHTML, most of which have to do with the simple fact that most web servers don't serve it as XML and most browsers don't read it as XML, but that's a different article for a different day. Today, we're using XHTML 1.0 Strict because the client insists that we use the latest technology regardless of whether or not it's appropriate; so this is what the DOCTYPE definition for XHTML 1.0 Strict looks like:


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

Remember, that's the very first line of your file!

Next, let's get the basic xhtml in there:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
  <meta http-equiv="Content-Type" 
        content="text/html; charset=UTF-8"/>
 </head>
 <body>
 </body>
</html>

Next, let's get some very basic SEO framework in there and add some meta elements. Meta elements are sometimes called meta tags, but since we're working in an XHTML document we'll use the XML terminology. We'll use description and keywords, and throw author in the for good taste.


<meta name="keywords" 
      content="page, site, title, keyword, doctype"/>
<meta name="author" 
      content="Eric DeLabar"/>
<meta name="description" 
      content="A short description of the page content."/>

Great, now there's a place for keywords and a description, but why do we need them? Keywords are old-school, I don't even know if modern crawlers still look at them, but I do know that like all meta elements they should be specific for the page you're writing them for. So, as a means of guiding my SEO, I usually choose the 5-10 keywords that I want to apply to my current page, then make sure that as I'm writing the page copy I use those keywords.

The description meta element is slightly different, because it's visibly used. It is displayed by some search engines as a description of your page when it occurs as a result. As a guide to writing a description, keep it short, around 128-256 characters. Keep in mind that if it's too long it will most likely by truncated, so just write a sentence describing the current page.

Now, we'll have a look at the page title:


<title> Descriptive Page Title - EricDeLabar.com</title>

Like the meta description, the title element is displayed as part of a search result list, so a descriptive title can be very helpful for drawing users into your site. Some SEO experts also believe that keywords in your title are more heavily weighted in search rankings. Keep the title shorter than your description, and maybe consider including your branding at the end. I like the branding at the end because if it does get truncated by the search engine more of my more important descriptive title is displayed.

Finally, let's add the stylesheets:


<link rel="stylesheet" type="text/css" 
      href="/style/screen.css" media="screen"/>
<!-- [if lte IE 6]>
<link rel="stylesheet" type="text/css" 
      href="/style/iefix_screen.css" media="screen"/>
<![endif]-->

Now I'm a bit of a purist, and I'll have a later post describing my process for styling a page, but notice for now, I usually have a minimum of two stylesheets. The first being a clean stylesheet (as in NO Hacks/Filters/Whatever you like to call them) that handles all of the (mostly) standards complaint browsers, then an Internet Explorer conditional comment for handling older versions of IE. In this case, my iefix stylesheet is for lte IE 6 which translates to Less than or equal to Internet Explorer 6. Notice that the iefix stylesheet comes after the other stylesheet(s), this is so that any rules in the iefix stylesheet with equal or greater CSS specificity will overwrite the rules in the standard stylesheet. (More on specificity in a later post.)

That's it! Congratulations, you have a nice, clean base to start your web 2.0 website on! If you're curious, the finished product looks something like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
  <meta http-equiv="Content-Type" 
          content="text/html; charset=UTF-8"/>
  <meta name="keywords" 
        content="page, site, title, keyword, doctype"/>
  <meta name="author" 
        content="Eric DeLabar"/>
  <meta name="description" 
        content="A short description of the page content."/>
  <title> Descriptive Page Title - EricDeLabar.com</title>
  <link rel="stylesheet" type="text/css" 
        href="/style/screen.css" media="screen"/>
  <!-- [if lte IE 6]>
  <link rel="stylesheet" type="text/css" 
        href="/style/iefix_screen.css" media="screen"/>
  <![endif]-->
 </head>
 <body>
 </body>
</html>

No comments: