HTML The Definitive Guide (21 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
7.58Mb size Format: txt, pdf, ePub

portions of the document, but don't themselves appear in the display.

Accordingly, new HTML authors are confronted with having to develop not only a presentation style for their HTML pages, but a different style for their HTML source text. The source document's layout should highlight the programming-like markup aspects of HTML, not its display aspects. And it should be readable not only by you, the author, but by others, as well.

Experienced HTML document writers typically adopt a programming-like style, albeit very relaxed, for their source HTML text. We do the same throughout this book, and that style will become apparent as you compare our source HTML examples with the actual display of the document by a browser.

Our formatting style is simple, but serves to create readable, easily maintained documents: Except for the document structural tags like ●

, , and , any HTML

element we used to structure the content of a document is placed on a separate line and indented to show its nesting level within the document. Such elements include lists, forms, tables, and similar tags.

Any HTML element used to control the appearance or style of text is inserted in the current line ●

of text. This includes basic font style tags like (bold text) and document linkages like (hypertext anchor).

Avoid, where possible, the breaking of a URL onto two lines.


Add extra newline characters to set apart special sections of the HTML document; for instance, ●

around paragraphs or tables.

The task of maintaining the indentation of your source HTML ranges from trivial to onerous. Some text editors, like Emacs, manage the indentation automatically; others, like common word processors, couldn't care less about indentation and leave the task completely up to you. If your editor makes your life difficult, you might consider striking a compromise, perhaps by indenting the tags to show structure, but leaving the actual text without indentation to make modifications easier.

No matter what compromises or stands you make on source code style, it's important that you adopt one. You'll be very glad you did when you go back to that HTML document you wrote three months ago searching for that really cool trick you did with. . . . Now, where was that?

2.13 Forging Ahead

3.2 Structure of an HTML

Document

Chapter 3

Anatomy of an HTML

Document

 

3.2 Structure of an HTML Document

An HTML document consists of text, which defines the content of the document, and tags, which define the structure and appearance of the document. The structure of an HTML document is simple, consisting of an outer tag enclosing the document head and body:


Barebones HTML Document


This illustrates, in a very simple way, the basic structure of an HTML document.



Each document has a
head
and a
body
, delimited by the and tags. The head is where you give your HTML document a title and where you indicate other parameters the browser may use when displaying the document. The body is where you put the actual contents of the HTML

document. This includes the text for display and document control markers (tags) that advise the browser how to display the text. Tags also reference special-effects files, including graphics and sound, and indicate the hot spots (
hyperlinks
and
anchors
) that link your document to other documents.

3.1 Appearances Can Deceive

3.3 HTML Tags

Other books

Ruthless by Jonathan Clements
Sleeping With Santa by Debra Druzy
Facing the Music by Jennifer Knapp
The Little Bride by Anna Solomon
The Last Goodbye by Reed Arvin
Dead Night by Tim O'Rourke