Member Sign In
Not a member?

A Wired.com user account lets you create, edit and comment on Webmonkey articles. You will also be able to contribute to the Wired How-To Wiki and comment on news stories at Wired.com.


It's fast and free.

Sign in with OpenID
Sign In
Webmonkey is a property of Wired Digital.
processing...
Join Webmonkey

Please send me occasional e-mail updates about new features and special offers from Wired/Webmonkey.
Yes No

Please send occasional e-mail offers from Wired/Webmonkey affiliated web sites and publications, and carefully selected companies.
Yes No

I understand and agree that registration on or use of this site constitutes agreement to Webmonkey's User Agreement and Privacy Policy.
Webmonkey is a property of Wired Digital.
processing...

Retrieve Sign In

Please enter your e-mail address or username below. Your username and password will be sent to the e-mail address you provided us.

or
Webmonkey is a property of Wired Digital.
processing...

Welcome to Webmonkey

A private profile page has been created for you.
As a member of Webmonkey, you can now:
  • edit articles
  • add to the code library
  • design and write a tutorial
  • comment on any Webmonkey article
Close
Webmonkey is a property of Wired Digital.

Sign In Information Sent

An e-mail has been sent to the e-mail address registered in this account.
If you cannot find it in your in-box, please check your bulk or junk folders.
Sign In
Webmonkey is a property of Wired Digital.

Validate Your HTML

/skill level/
/viewed/
0 Times

If you're anything like us, you're always jumping on your cross-platform soapbox at the office. On mailing lists, over lunch, at parties, and on the bus home from the party (just in case the bus driver has been duped into supporting proprietary tags in his home page) you insist that everyone should follow W3C standards for HTML, CSS, and HTTP.

"Standards, standards, standards!", you insist, as you pound on your podium. But do you actually test your own Web site for rigid W3C compliance? Be honest: Of course you don't. You look at it with a couple of browsers, maybe a second computer, and just fix anything that looks wrong to your naked eye.

But if you really want to create cross-platform HTML and remove proprietary browser tricks from your site, you should be validating your HTML with the W3C's HTML validator at validator.w3.org. The W3C validator is free to use and always up to date. And a more official source for standards specifications doesn't exist.

Even better, you can augment the W3C specifications to include your own rules, such as forbidding nested tables. A "house rules" validator is an easy way to keep a team of developers from messing up each others' work.

Contents

How to Use the Validator

Using the validator requires one modification to your pages:It will complain if you don't embed a DOCTYPE tag at the very top of every page you want to validate, stating what "document type definition" (DTD) your document conforms to. Without that tag, the validator will try to guess which HTML standard you are trying to comply with. But to be fully W3C compliant you must put this line at the top of your page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 

or for documents with frames:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">

Then open validator.w3.org. Enter the URL of your page into the box labelled "URI" (don't ask why it says "URI" instead of "URL" or this column will get a lot longer), and hit Return. Almost instantly, you'll get a list of all the HTML errors on your page, with a link to a standard explanation for each, like this:

Error at line 25:</head>

[1] end tag for element "HEAD" which is not open

Figuring out how to fix the errors is up to you and can be time-consuming. The explanations aren't always helpful for struggling developers, and we haven't figured out a way to get the validator to stop complaining for pages and pages about questionable HTML in some of the ad banners we don't create ourselves. As a workaround, we created fake, validated ad HTML fragments, and replace the ad server calls with these in pages we want to validate while developing them.

Congratulations - You Get a Button!

Once you've fixed all your errors, running your page through the validator will reward you with this button:

[2] Congratulations, this document validates as HTML 4.0 Transitional!


To show your readers that you've taken the care to create an interoperable Web page, you may display this icon on any page that validates.

A Couple of Catches

One small problem with the W3C validator is that it won't work on pages hiding behind a firewall. If you aren't comfortable copying your pages under development to somewhere outside your firewall, there are local validation tools you can use, such as the ones that come with Doctor HTML or HomeSite. Once your pages are live to the world, you can run them through the W3C site.

Another problem you'll encounter is pages that call in ad banners from an ad server. Your page may be standards-compliant, but there's no way to guarantee that the ads scheduled for it will be. Fixing them all yourself, or getting all your advertisers to comply, just isn't going to happen. To make it worse, many ad servers use "&" to separate CGI parameters. Ampersands in URLs are verboten in the HTML 4.0 standard. Good luck getting your US$50,000 ad server software changed.

But the most aggravating problem you'll discover with validating your HTML is this:Meeting the W3C specifications doesn't mean that all browsers will agree on how to render your page. You can end up with pages that are standards-compliant, but which lay out differently on Navigator 3 for Linux, or Internet Explorer 4 for Macintosh. This can be unacceptable to a designer who wants exact control over each pixel. You may have to do some evangelizing (or just old-fashioned complaining) in order to avoid using browser-specific HTML in the long run.

Writing valid HTML can be a lot of work up front, especially if you're retrofitting old content. To be honest, this column itself fails the 4.0 Transitional test. But if you can put the work in, and win a few fights with your co-workers over standards, a trip to validator.w3.org now will save you a lot of catch-up work down the road.

Introduction

What you'll need

Steps

Alternate methods

Suggested readings

  • This page was last modified 18:23, 11 May 2008.
Edit this article
Reddit Digg
 
Subscribe now

Special Offer For Webmonkey Users

WIRED magazine:
The first word on how technology is changing our world.

Subscribe for just $10 a year