Chapter 3. Adding Style Sheets to Documents

Like their counterparts in word processing and desktop publishing programs, HTML style sheets are supposed to simplify the deployment of fine-tuned formatting associated with content. Instead of surrounding every H1 element in a document with <FONT> tags to make all of those headings the same color, you can use a one-line style definition in a style sheet to assign a color to every instance of the H1 element on the page. Of course, now that style sheets make it easier to specify colors, margins, borders, and unusual element alignments, you are probably adding more HTML elements to your documents. So your documents may not be any smaller, but they should be more aesthetically pleasing, or at least closer to what you might design in a desktop publishing program.

Rethinking HTML Structures

In order to successfully incorporate style sheets into HTML documents, you may have to reexamine your current tagging practices. How much you’ll have to change your ways depends on how and when you learned HTML in the first place. Over the years, popular browsers have generally been accommodating with regard to—how shall I say it—less-than-perfect HTML. Consider the <P> tag, which has long been regarded as a single tag that separates paragraphs with a wider line space than the <BR> line break tag. HTML standards even encourage this start-tag-only thinking by making some end tags optional. You can define an entire row of table cells without once ...

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.