By Chuck Musciano, Bill Kennedy
Cover | Table of Contents | Colophon
<html> <head> <title>My first HTML document</title> </head> <body> <h2>My first HTML document</h2> Hello, <i>World Wide Web!</i> <!-- No "Hello, World" for us --> <p> Greetings from<br> <a href="http://www.ora.com">O'Reilly & Associates</a> <p> Composed with care by: <cite>(insert your name here)</cite> <br>©2000 and beyond </body> </html>
<) and
greater-than (>) characters. [Section 3.3.1]
<i> tag that follows the
word "Hello" in the simple example
tells the browser to display the following text in italics. [Section 4.5]
=), which further
define or modify the tag's actions.
/ ). For example, the end tag that matches the
"start italicizing"
<i> tag is </i>.
<html>
and
</html> tags. These tags tell the browser
that the entire document is composed in HTML. The HTML and XHTML standards require an
<html> tag for compliant documents, but most
browsers can detect and properly display HTML encoding in a text
document that's missing this outermost structural
tag. [<html>]
<title> and
</title> tags in your
document's header. The popular browsers typically
display the title at the top of the document's
window. [<title>]
<html>, <head>,
<body>, and <title>
tags, the HTML and XHTML standards have few other required structural
elements. You're free to include pretty much
anything else in the contents of your document. (The web surfers
among you know that authors have taken full advantage of that
freedom, too.) Perhaps surprisingly, though, there are only three
main types of HTML/XHTML content: tags (which we described
previously), comments, and text.
<!-- and ending tag -->
comment delimiters, gets included in the browser display of your
document. You see a comment in the source, as in our simple HTML
example, but you don't see it on the display, as
evidenced by our comment's absence in Figure 2-1. Anyone can download the source text of your
documents and read the comments, though, so be careful what you
write. [Section 3.5.3]
<img>; its required
src
attribute is the URL of the GIF or JPEG image you want to insert in
the document. [<img>]
<img>
align
attribute, whose value you set to put the image at the
top
, middle, or
bottom of adjacent text. Examine Figure 2-2 through Figure 2-4 for the
image alignment you prefer. Of course, wide images may take up the
whole line and hence break the text flow. You can also place an image
by itself, by including preceding and following division, paragraph,
or line-break tags.
<ul> and
</ul> tags. Each item in the list, usually a
word or short phrase, is marked by the <li>
(list-item) tag and, particularly with XHTML, the
</li> end tag. When rendered, the list item
typically appears indented from the left margin and preceded by a
bullet symbol. [<ul>] [<li>]
<ol> and </ol>
tags, are identical in format to unordered ones, including the
<li> tag (and </li>
end tag with XHTML) for marking list items. However, the order of
items is important — equipment assembly steps, for instance. The
browser accordingly displays each item in the list preceded by an
ascending number. [<ol>]
<dl> and
</dl> tags, each list item has two parts,
each with a special tag: a short name or title, contained within a
<table>
tag itself and a
<caption>
tag for including a
description of the table. Special tag attributes let you change the
look and dimensions of the table. You create a table row by row,
putting between the table row
(<tr>
)
tag and its end tag (</tr>) either table
header
(<th>
) or table data
(<td>
) tags and their
respective contents for each cell in the table (end tags, too, with
XHTML). Headers and data may contain nearly any regular content,
including text, images, forms, and even another table. As a result,
you can also use tables for advanced text formatting, such as for
multicolumn text and sidebar headers (see Figure 2-5). For more information, see Chapter 10.
<body> tag with one or more
<frameset>
tags that tell the browser how to divide its main window into
discrete frames. Special
<frame>
tags go inside the
<frameset> tag and point to the documents
that go inside the frames.
<html>
<head>
<title>CSS Example</title>
<!-- Hide CSS properties within comments so old browsers
don't choke on or display the unfamiliar contents. -->
<style type="text/CSS">
<!--
H1 {color: red}
-->
</style>
</head>
<body>
<H1>I'll be red if your browser supports CSS</H1>
Something in between.
<H1>I should be red, too!</H1>
</body>
</html><H1>-enclosed
text appears red on a color screen.
<html>,
<head>, and <body>,
any element we use 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.
<b> (bold text) and document
linkages like <a> (hypertext anchor).
<html>
tag enclosing the
document head and body:
<html> <head> <title>Barebones HTML Document</title> </head> <body> This illustrates, in a very <i>simp</i>le way, the basic structure of an HTML document. </body> </html>
<head> and <body>
tags. The head is where you give your 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
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.
<i> and
</i> tags respectively tell the browser to
start and stop italicizing the text characters that come between
them. Accordingly, the syllable
"simp" in our barebones example
above would appear italicized on a browser display.
< and
>). The simplest tag is nothing more than a
name appropriately enclosed in brackets, such as
<head> and <i>.
More complicated tags contain one or more
attributes, which specify or modify the behavior
of the tag.
<head>,
<Head>, <HEAD>, or
even <HeaD>; they are all equivalent. With
XHTML, case is important: all current standard
tag and attribute names are in lowercase.
=) after the attribute name. You may include
spaces around the equals sign, so that width=6,
width
=
6,
width
=6, and
width=
6 all mean the same. For
readability, however, we prefer
not to include spaces. That way, it's easier to pick
out an attribute/value pair from a crowd of pairs in a lengthy tag.
<br> and <hr>
for which the HTML standard forbids the use of an end tag. With
XHTML, the ending is placed inside the start tag:
<br
/>, for example.
[Section 16.3.3]
<head> is acceptable, and it is
not the same as <HEAD>
or <HeAd>, as it is with the HTML standard.
[Section 16.3.4]
<p> can
mean the beginning of a paragraph in HTML, whereas another variant of
the language may define the contents of the
<P> tag to be election-poll results that
display quite differently — perhaps in tabular form, with red,
white, and blue stripes and accompanying patriotic music.
<). In
HTML, it normally signifies the start of a tag, so if you insert it
simply as part of your text, the browser will get confused and
probably misinterpret your document.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html> and </html>
tags serve to delimit the beginning and end of a document. Since the
typical browser can easily infer from the enclosed source that it is
an HTML or XHTML document, you don't really need to
include the tag in your source HTML document.