HTML and CSS Reference
In-Depth Information
builds on well-formedness.
A document can be invalid in an infinite number of ways. In this chapter, I'll focus on some of the most common
problems you're likely to need to fix. Once you have valid pages, you will be ready to move on to the next
steps, and you can begin to work on improving the appearance, accessibility, and usability of your site.
Introduce a Transitional DOCTYPE Declaration
Insert the XHTML transitional DOCTYPE declaration at the start of each document.
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Motivation
The transitional DTD enables you to validate the document while not immediately requiring fully semantic
markup. It still allows documents to include deprecated presentational elements such as i , b , and center . Thus,
you can find and fix any serious structural problems before moving on to improving the semantics of your
document.
Potential Trade-offs
Browsers that use the presence or absence of a DOCTYPE to select quirks mode may format the document
somewhat differently after you've added the DOCTYPE. Although changes should not be major, you should
manually inspect pages to make sure nothing too serious has changed. The most likely things to break are any
browser-specific hacks you've installed, especially ones intended for Internet Explorer.
Mechanics
The first step to making a document valid is to add a document type definition, or DTD. Technically, you don't
add the DTD itself to the document. Rather, you add a DOCTYPE declaration that points to the document type
definition. The DOCTYPE declaration will be the first item in the document, even before the root element. For
example:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
In practice, browsers never actually read the DTD that the DOCTYPE declaration references. They simply check
the public identifier to see which variant of HTML they're dealing with. Thus, you don't need to worry that this
points to an external file on an external server. This will not slow down document display in the browser.
XML parsers and other XML tools do read the DTD, though. If you're using any of these, you may wish to point
to a local copy of the DTD instead. For example, this DOCTYPE asserts that the transitional DTD can be found at
Search WWH ::




Custom Search