The head section of an HTML document is not specifically required; unless one is explicitly declared, all content of an HTML document is considered to be part of the body. Since the head is not required, most basic users of HTML don't create a head on their documents for their personal Web pages. For now, we won't put an exhorbitant amount of detail into the head, but it does seem cool to have your name or the name of your Web site in the title bar of your document.
���
������Step-by-Step HTML: Head and Body
���
In the sample HTML document you made on the previous page, put a head into the document and put a title in the head. You may want to indent your code like the example shows so that it's easier to read later on. The tags nest inside each other in a heirarchy, and the browser will interpret them that way. The head isn't the greatest place to illustrate this, so let's go into the body of the document.
As mentioned before, tags are heirarchical and are interpreted as such. Luckily, this can sometimes help you diagnose display problems if your page doesn't appear as you intended. For instance, I want to display a movie title with the main title in bold text, centered in the browser window. The first part of the title should be bold, but the subtitle is supposed to be in italics. is used to create italic text, is used for bold,
creates a new line, and
At first glance, this might make sense. The
���
������Movies I Hope Not To See
���
���
������Major League XVII:
������
������Playing Catch With the Grandkids
���
Not quite what we had in mind; the second line should only be italicized, but the whole thing should be centered. How about using the indentation to our advantage, to create a visual cue that will alert us ahead of time?Major League XVII:
Playing Catch With the Grandkids
Which results in:
���
������Movies I Hope Not To See
���
���
������
���������Major League XVII:
���������
���������Playing Catch With the Grandkids
������
���
That's better! Still not a movie I'd care to watch, but it's formatted the way I had intended it. Looking at the previous examples, can you see why the text appeared as it had? The tag will continue to make text bold until its closing tag, , is found. The other tags work the same. By making our source code, in other words the text version of the HTML document, a heirarchy of indented paragraphs, it was more visually apparent what would be centered, what was bold, and what was italicized. No matter if you are writing HTML or programming in a complex computer language, always make sure to make the source code easy to read. It pays off dividends later.