Just as CSS has had several versions, so too has HTML. To use the W3C valida-
tor, you must specify at the top of an HTML document which version you’re
using before validating it. That way, the validator knows how to analyze your
code. Declare your documents as HTML-4 compliant. (HTML 3 doesn’t allow
span, ID, style, or classattributes, among other shortcomings.) You’d really
cramp your CSS styles if these attributes are missing, right? And if you’ve got
them in your code, the HTML validator lists them as errors unless you specify
HTML-4.
Go to this address for the HTML validator:
http://validator.w3.org/
If your Web page is already on the Internet, you can validate it by giving its
URL (or URI, as the W3C calls it) address. The information that appears in the
Address field of Internet Explorer when you visit a Web page is its URL.
If you’re still working on your page and haven’t published it yet, you can
browse to an .htm file on your hard drive, just as you browsed to a .css file
in the example earlier in this chapter of CSS validation.
Meeting some requirements ............................................................
The HTML validator wants to know two things about your document: which
version of HTML are you using (4 is the right answer) and which flavor (strict,
transitional, or frameset). Strictmeans you aren’t using any questionable or
recently deprecated HTML code (code that’s frowned-upon or intended for
eventual replacement). Transitionalmeans you’re using some of the deprecated
tags. If you want to include framesets, you have to specify that flavor. I suggest
you use the loose transitional or frameset flavor. Here’s what you should insert
at the topof your .htm file (above the <html>tag):
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01
Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
As you know after trying the various examples in this book, the browser
doesn’t care about the doctype “declaration” info. Some validators,
though, do.
For a way to use !DOCTYPE to force IE (or other browsers) to be CSS
standards-compliant, see Chapter 11, or take a look at this online discussion:
http://msdn.microsoft.com/library/default.asp?url=/library/en
-us/dnie60/html/cssenhancements.asp
310 Part IV: Advanced CSS Techniques