Working with HTML Text 113
Formatting
Text
Working with HTML Text
Web Design in a Nutshell, eMatter Edition
Paragraphs and Line Breaks
Line breaks that occur in the HTML source document are ignored when rendered
by a web browser. HTML text wraps text automatically to fill the width of the
browser window (or table cell). When the window is resized, the text is reflowed
to fill the new width. Lines will break in different places (with fewer words per
line) for a user who has the default type size set very large than for a user with
small default type.
In HTML, you must deliberately specify where you want a line to break. This is
most often done by indicating paragraphs and headings (both are examples of
block-levelelements), which automatically add line breaks with extra white space
above and below. If you want to break a line but not add any extra space, insert a
line break with the
tag.
The following two figures show the difference between lines broken with a
tag and a
. In Figure 7-1, the line is broken by a
and extra space is intro-
duced. In Figure 7-2, the
tag breaks the line but does not add space.
Most elements on a web page are contained within paragraphs, which, according
to the HTML standard, should be enclosed in the
and
tags. However,because browsers are clever enough to infer that a new opening tag indicates the
end of the previous paragraph, many web authors leave off the closingtag
and insert
s as though they were line spaces.
This is fine for most current web purposes, but it should be noted that lax coding
may not be as tolerated in future web page description languages or for browsers
such as Opera that adhere to HTML standards strictly. It is already important to tag
paragraphs properly for use with Cascasding Style Sheets. XML promises to be
quite particular about closing tags as well. It’s probably not a bad idea to get into
the habit of closing all the tags you once left hanging.
Figure 7-1: Breaking text with the
tag adds vertical spacing
Figure 7-2: Breaking text with the
tag doesn’t add vertical spacing
<P>The quality of a finished cake can only be as good
<P>as the quality of the raw materials used in it.
<P>The quality of a finished cake can only be as good
<BR>as the quality of the raw materials used in it.