How To Make a Web Site the Modern Way. Part 2: The Head
by Rob Larsen
Last time out we looked at the Anatomy of a Web Page. Using that, let’s move on and look at the first of the two major sections, the head.
For the sake of this blog post, the head includes two pieces of code that are actually before the head. Sue me
Using the head from my (recently updated) starter assets project as an example, let’s look at the code in detail. First, what it looks like in total:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--[if gte IE 7]>
<![if IE 7]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie ie7" lang="en" >
<![endif]>
<![if gt IE 7]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie ie8" lang="en" >
<![endif]>
<![endif]-->
<!--[if !IE]> <-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
<!--> <![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Change This Title</title>
<meta http-equiv="X-UA-Compatible" content="IE=8;chrome=1" >
<meta name="robots" content="index, follow" />
<meta name="description" content="" />
<link rel="shortcut icon" href="" />
<link rel="stylesheet" href="_assets/styles/styles.css" />
<!--[if gte IE 5.5]>
<![if lt IE 7]>
<link rel="stylesheet" href="_assets/styles/ie6.css" />
<![endif]>
<![endif]-->
</head>
If that doesn’t make sense to you, don’t worry, it will after I go through it. Well, the bits that need to make sense will.
Let’s start at the top and work our way down.
Doctype Declaration (DTD)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
I could explain what this nonsensical string means, but I won’t.
All you need to know is that it tells the browser what type of HTML document we’re serving.
Yes, there are different types of HTML. Why that matters isn’t important right now as all the flavors use basically the same patterns, so we can look at structure without worrying about flavor-specific differences too much.
Don’t worry about learning the above, by the way. There’s plenty of HTML to learn, the DTD isn’t one of them. If, for some reason, you ever need to make an HTML document from scratch, search for “xhtml doctype” (or “html 4 doctype”) and copy and paste the result.
This example uses the xHTML 1.0 Strict Doctype. Other flavors are:
HTML 4.01 Doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
HTML5 Doctype
<!DOCTYPE html>
My favorite is clearly the HTML5. Beyond my excitement over the specification itself, I like the fact that it’s easy for me to remember.
Why you would want to use one Doctype over another over is something I’ll cover at a later date.
For now we’re just going to continue the tour of the head confident in the fact that we’ve signaled to the browser our intention to use xHTML 1.0.
Fancy.
The HTML Element
Before I get into my specific example, which has some complicated stuff attached to it in order to make our lives easier later on, I’ll show you what a regular, xHTML opening html tag looks like:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
Now let’s look at my fancy version:
<!--[if gte IE 7]>
<![if IE 7]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie ie7" lang="en" >
<![endif]>
<![if gt IE 7]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie ie8" lang="en" >
<![endif]>
<![endif]-->
<!--[if !IE]> <-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
<!--> <![endif]-->
What’s going on there? Without getting too far into the details of conditional comments, the above defines three separate opening html tags.
- One for Internet Explorer 7. Two classes are added to the
htmlelement- “ie” and “ie7″ - One for Internet Explorer 8. Two classes are added to the
htmlelement- “ie” and “ie8″ - One for every other browser. No classes are added to the
htmlelement
Why do that? Well, with the classes on the html element it’s easy to target CSS fixes for both of the Internet Explorer versions in your style sheet (we’ll deal with IE6 later.)
More on this kind of stuff later, when we talk about CSS.
Just remember that we we made something easy without sacrificing much at all.
Easy is good.
One other thing to note is the lang="en" attribute. That sets the language of the document to English. If you’re authoring documents in languages other than english familiarizing yourself with the various language codes is time well spent.
The head
This is the actual head, as opposed to the other stuff which is warm-up for the head itself.
As I mentioned before, the head generally contains information computers read about a document. You’ll see what that means more clearly as I work my way through the next few elements. Let’s look at each of them in turn.
HTTP-EQUIV
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
In our xHTML example we’re indicating the type of content (text/html) and the character set the document is encoded in (utf-8) using the http-equiv attribute of the meta tag. These are equivalent to HTTP headers. If that doesn’t mean anything to you, don’t sweat it, there’s only one bit you need to really pay attention to in this string- the charset (short for character set). Character sets are important. Far too important to go into here where I’m trying to be really broad and not so deep.
I’ll sum it up thusly, UTF-8 is a pretty good choice for international content (and at the end of the day what content on the web isn’t international content.)
Except when it’s not. The good thing is, you’ll know when it’s not as your text will look all funny.
If you’re serious about making web sites, read this article for more about character encoding than you probably ever wanted to know… It’s an important topic so folks should really take some time to familiarize themselves with the issues at play.
The Title
<title>Change This Title</title>
The title is just that- the title of the page. You can see it in the title bar of your browser.

The title is one place where there are primal Search Engine Optimization (SEO) issues.
For starters search engines only show 60-70 characters, so keep your titles within that range. Additionally, they should be unique across your site, should contain the site name, and should reference pertinent keywords to the document content.
Check out SEOMoz’s SEOmoz’s Best Practices for Title Tags for an in-depth look at how to handle title tags.
X-UA-Compatible
<meta http-equiv="X-UA-Compatible" content="IE=8;chrome=1" >
This is an IE-specific tag that says “Please render this page in IE8 mode. If that’s not available, I’ll use Google Chrome Frame.”
Which does two things in the two browsers that understand it. In IE6 with Google Chrome Frame, it turns on the power of Chrome in IE6, turning all of our frowns upside down. In IE8 it forces the browser into IE8 Standards mode. AKA, the best Microsoft has to offer. If you’re doing standards based development that’s the IE8 mode you want.
Robots
<meta name="robots" content="index, follow" />
This meta tag simply tells Search Engine spiders to index (save the file in their database) and follow links present on the page (to find more pages for their database.) If you’re doing development on a net accessible server it’s good to turn this off (with noindex, nofollow), just in case the pages are somehow discovered. Just don’t forget to flip the switch when you go live
Meta Description
<meta name="description" content="" />
Think of this as an ad for the page you’re making. In a lot of ways it is, as Google will often (but not always) use the meta description as the text on search engine results pages (affectionately known as SERPs.) Keep it to less than 155 characters.
Shortcut Icon/favicon
<link rel="shortcut icon" href="icon.png" />
Ever wonder about the little icon next to the URL in the address bar? This is a link to that file. I use a nifty PNG.
The Style Sheet
<link rel="stylesheet" href="_assets/styles/styles.css" />
And now we attach a style sheet. Fun times. More about CSS later
And Now, Internet Explorer 6
<!--[if gte IE 5.5]>
<![if lt IE 7]>
<link rel="stylesheet" href="_assets/styles/ie6.css" />
<![endif]>
<![endif]-->
</head>
This little bit of code attaches a separate style sheet for Internet Explorer 6 (and 5.5, but that’s a rare, rare browser now.) I do this because the rules for IE6 can occasionally become, well, insane and I want to keep IE6 style insanity out of my regular style sheet.
And there you have it, a quick jaunt through the head of the document. Next up, a quick interlude dealing with file structures and then it’s onto the body and some HTML markup that users will actually see.
The Rest of the Series
- Javascript: Parse Domain Name out of a String
- Code : Javascript : Turn a block into a clickable link area.
- Need/Want to Hide Internet Explorer 6 Specific JavaScript from IE7?
- Cross Browser PNG Transparency: Part 2
- The joy of... JavaScript's getElementsByTagName()
- Javascript: getElementById() for XML fragments and arbitrary XML documents + getElementsByAttribute()
- Mad Science... Flash for a page background using JavaScript and CSS
- Answering Google- Passing a Random Number to a Div id in Javascript
- Cross Browser Opacity using CSS and Internet Explorer filters
- CSS Attribute Selectors. I'd like to be able to use them.
- Display: inline-block is the bee's knees. CSS 2.1
- JSON Feeds For Fun and Profit, Part One- Del.icio.us makes it easy
- JSON Feeds For Fun and Profit Part 2 - Callbacks with Twitter
- The difference between javascript's getElementById() and getElementsByName()
- Automatically Track Outgoing Links in Google Analytics with Javascript
- Did you know- 8 Bit PNG transparency is just like an old school transparent Gif
- A Three Column CSS Layout Using Just an Unordered List
- Belt and Suspenders- Flash Embed With SWFObject and Conditional Comments
- JSON Feeds For Fun and Profit Part 3- wherein Eval() kind of bums me out
- Why Did I Never Try this Before? CSS Font-Size : 0 Hides Input Button Text
- Setting Far Future Expires Headers For Images In Amazon S3
- YSlow Performance Grades for 200 Top Web Sites
- Acid3 Test Released. I Took Some Screen Captures. Lots of Fail.
- Yahoo! Posts an Interesting Illustration of the Lang Attribute.
- Using overflow:auto to Clear Floated Content in CSS
- Best Lightweight Web Server for Serving Static Content?
- Say Hello to JavaScript's Native getElementsByClassName
- Some Internet Explorer Innovations You Probably Forgot About While Waiting for IE6 To Die
- Code I Like: Using Apache's .htaccess and mod_rewrite to Redirect All Traffic to "www"
- Twitter Search Results With JSON and Callbacks
- Code I Like - Link Prefetching
- Two Easy Ways to Get Set Up With Amazon's CloudFront
- Why Front End Performance Matters to Everyone, Not Just the High Traffic Giants
- Code I Like: Batch Subversion Rename (Replace Underscore with Hyphen), Bash Script
- A JavaScript Curiosity Regarding addEventListener
- What This is All About
- Google Releases Page Speed (and I add a few lines to my to-do list)
- HTML5 I'm Using Today- Custom Data Attributes
- On My Radar This Week- Cufon, Event Tracking, Steve Souders' New Book
- I Think I'm Going to Start Dreaming in Wordpress
- Tom Okeefe, Interviewed at Fireworks Designer
- I'm Presenting at the Center for Digital Imaging Arts at Boston University, July 14
- In Case You Missed It- Google Talks Web Performance
- YUI 3.0.0 beta 1 Available for Download
- The Wait For the Palm WebOS SDK
- Recent Reading (HTML5, CSS Fonts, JavaScript, rel=nofollow, Google Analytics)
- getElementsByTagName Namespace Prefix Strangeness in Safari/Chrome/WebKit
- Of Interest- the Google Chrome Operating System
- getElementsByTagNameNS. Now I Know. And Knowing is Half the Battle.
- I Don't Care About Developers. I Care About Users.
- Presentation Done. Thanks to all Who Attended.
- The Palm webOS SDK is Now Open To All. Get Your Mojo On!
- Fun With the :Hover Pseudo Class and Code Samples
- I'm Happy That This One is Live
- Sometimes, Dreamweaver Surprises Me- Great Accessibility Enhancement
- JavaScript Library Showdown. Video of my CDIA Presentation is Live. Check It Out!
- While Twitter is Down...
- Webinar: Increase the Performance of Your Website With Amazon CloudFront
- Even Faster Web Sites (Review)
- How Difficult Is It To Avoid Expensive CSS Selectors?
- Setting Up My Own URL Shortening Service
- An Update on My URL Shortener
- JavaScript Perfromance Tip- Don't Test Against obj.length. Test Against a Local Variable.
- HTML 5 Notes: In Case a Client Asks... No Full Screen Video
- HTML 5 Notes: The Video Element Rocks
- As If URL Shorteners Alone Weren't Bad Enough, Now They've Mated With URL Hijacking Frames
- HTML5 Notes: My First Time Using the Canvas Element
- File Under Cool Tools: Record Page Load Video With WebPageTest
- HTML5 Demo: Tracking Video Progress With Google Analytics
- Why I Dumped Tweetdeck For Brizzly
- HTML5 With Modernizr... Come on in! The Water's Fine.
- I Love You, border-radius. You Too, box-shadow. No, I Didn't Forget About You, rgba Color!
- I'm Finally Building a WebOs App
- Google Chrome Frame- I'll Be Taking Advantage Of It
- I, For One, Welcome Our New CSS3 Overlords. As Long As They Bring box-sizing With Them.
- Thirteen Web Development Tools I Can't Live Without
- More Numbers On the Effect of Page Performance on the Bottom Line
- My Bookshelf. Books on JavaScript, Python, Linux, WebOS, etc.
- Sample HTML Markup Used To Style Common Text Elements
- Default HTML Rendering in 81 Browsers Visualized
- I'm Excited About the New Google Analytics Engagement Goals Feature
- Bing Launches Twitter Search (and I'm Writing About the Real Time Web Over At AWiderNet)
- Have I Mentioned That The HTML5 DOCTYPE Makes Me Smile?
- The JavaScript NodeList and You. Watch Where You Point That Thing, Soldier
- Jscript Versions Reported By Major Versions of Internet Explorer (For Use With Conditional Compilation)
- Netscape's Javascript Documentation From 1999 (document.layers!)
- Playing Around With Twitter Lists
- Google's Sitelinks vs. Bing's Deep Links + D-Card
- Want to Test Your Site Without a Mouse For Accessibility's Sake? These Keyboard Shortcuts Will Help
- Great New Google Webmaster Tools Feature - "Site Performance"
- What I Read This Week (jQuery's live(), algorithms, IE8 + VPN, Chrome )
- Microsoft's CSS Filters, Could The Syntax Be Any Uglier?
- I'm Presenting at WordCamp Boston January 23, 2010
- Browser Size, a Simple But Useful Tool From Google
- If I Lived in The Bay Area, I'd Go To These
- A New Site I Made is Live- AWiderNet.com (HTML5 + CSS3 + Wordpress)
- I'm Resolute
- In Case You Missed It...
- Recent Reading (30 Style Tags?, YUI 3, GodMode, Git, Jira)
- Rethinking the "How To Serve IE-Specific CSS" Question
- I'm Messing Around With an HTML5 Version of the Default Wordpress Theme
- Recent Reading (JavaScript Library CDNs, User-Agent Strings, Hacks, Hacks and Hacks)
- Two Front End Development Interview Questions No One Has Been Getting Recently + One I'm Afraid to Even Ask
- HTML5 + Wordpress Resource Links From my WordCamp Boston Presentation
- Some Photos From WordCamp Boston Posted to Flickr
- Short Notice- I'm Presenting at the Boston JavaScript Meetup This Thursday, January 28, 2010
- My Personal View of Browser Market Share is Pretty Sweet- Firefox Rules, Chrome is Massive, IE6 is Nearly Dead
- Video of My HTML5 + Wordpress Presentation From WordCamp Boston
- My Presentation From Last Night's JavaScript Meetup
- Starter Assets
- How To Make a Web Site the Modern Way. Part 0: Introduction
- How To Make a Web Site the Modern Way. Part 1: The Anatomy of an HTML Page
- Let Me Direct You to the Quote of the Week.
- How To Make a Web Site the Modern Way. Part 2: The Head
- Recent Reading (Analytics, WordPress Short Codes, Jira, JavaScript Videos, Protocol Relative URLS, Facebook)
- I'm on TV. WordPress.TV That Is.
- How To Make a Web Site the Modern Way. Part 3: A Quick Aside on Organizing Files
- How To Make a Web Site the Modern Way. Part 4: The Body
- DrunkenFist.com Redesign Launched. More HTML5 Goodness.
- How To Make a Web Site the Modern Way. Part 5: The Body - How To Structure Your Markup
- I'm Going to be Speaking on Front End Performance in May
- Recent Reading (node.js, P3PC, Event Delegation, Twitter)
- How To Make a Web Site the Modern Way. Part 6: Best Practices for Common HTML Elements (IMG, A)
- A Quick Examination of the Memory and Perfomance Ramifications of CSS Sprite Dimensions
- How To Make a Web Site the Modern Way. Part 7: Best Practices for Lists (UL, OL, DL)
- You Probably Didn't Notice - This Site is Now HTML5
- How To Make a Web Site the Modern Way. Part 8: Tables!
- How To Make a Web Site the Modern Way. Part 9: Tag (and Attribute) Soup
- How To Make a Web Site the Modern Way. Part 10: Forms
- In Case You Missed It:
- How To Make a Web Site the Modern Way. Part 11: The New HTML5 Elements
- Reminder- I'm Presenting on Front End Performance Next Week (May 19)
- Downloads From Last Night's Presentation
- Front End Performance for the Common Man: Practical Strategies to Speed Up Your Site
- Why Do I Like Web Performance? For One Thing, it's Easier to Measure Success
- Performance Tip: When Linking to JavaScript on the Google Ajax Library CDN, Use a Specific Version Number
- I Didn't Make it to Velocity, So Hours of Web Video Will Have to Do
- Required Reading: Yahoo Research on Mobile Cache Size
- I'm Going to Enjoy Writing Code for Internet Explorer 9 (I Can't Believe I Just Typed Those Words)
- Book Review: High Performance JavaScript
- I'm Presenting on CSS in October
- I Added Keyboard Navigation to my Site
- An Ant Task to Comment Out console.log Calls from JavaScript Files
- How To Make a Web Site the Modern Way. Part 12: Cascading Style Sheets
- How To Make a Web Site the Modern Way. Part 13: The Cascade/CSS Specificity
- I'm Going to be Presenting at Design Camp Boston
- HTML5: What You Should Be Using Right Now
- How To Make a Web Site the Modern Way. Part 14: Formatting, Shorthand, Resets and Organization
- Me, Talking About HTML5, Flash, and the Cloud as Part of the Isobar 50
Nicholas Yax Says:
February 16th, 2010 at 2:16 pm
Found your site after watching the HTML5 video on wordpress.tv and having a look around. Just wanted to point out that in the code, you specified a .pgn., not a .png file for your favicon. Might confuse some people.
Rob Larsen Says:
February 16th, 2010 at 2:22 pm
Thanks!
I’ll fix that now.
Thomas Junghans Says:
April 7th, 2010 at 3:23 am
Hi, I like the idea of giving ie browsers a different html tag with a specific css class for ie and the version.
One thing I’m missing in your head though is the following line which forces ie8 to run in ie8 standards mode.
Cheers
tj
Rob Larsen Says:
April 7th, 2010 at 7:59 am
@Thomas Thanks for the feedback, that’s a really good one.
If you view source on the site you’ll see I actually use the following here.
<meta http-equiv=”X-UA-Compatible” content=”IE=8;chrome=1″ >
I’ll add it to the tutorial.
How To Make a Web Site the Modern Way. Part 9: Tag (and Attribute) Soup » HTML + CSS + JavaScript » Blog Archive Says:
April 21st, 2010 at 1:46 pm
[...] we saw way back in the third entry in this series, your HTML document should signify its language on the opening html tag. Simple enough. So, what [...]