Chapter 6. Adding Text

Text is obviously an essential part of almost every web page. Though you can have a page or even a site completely devoid of text, they are the exception rather than the rule. HTML text is best handled in a structural fashion, with headings introducing paragraphs. In this lesson, you learn how to quickly add paragraphs, headings, and special characters to your web pages.

WORKING WITH PARAGRAPHS

In HTML, paragraphs of text are, aptly enough, contained in a <p>, or paragraph, tag. The <p> tag separates a text block from other elements, including other <p> tags. A paragraph tag can contain one or more sentences. For example, quotes from Henry David Thoreau formatted for the Web would look like this:

<p>Cultivate the habit of early rising. It is unwise to keep the head long on a
level with the feet.</p>
<p>Books are the carriers of civilization. Without books, history is silent,
literature dumb, science crippled, thought and speculation at a standstill.
I think that there is nothing, not even crime, more opposed to poetry, to
philosophy, ay, to life itself than this incessant business.</p>

By default, browsers typically render paragraph tags with a noticeable margin above and below the <p> tag content. In Firefox, the example text is depicted with one em of space on top and bottom as shown in Figure 6-1. Note the separation between the two paragraphs in the browser where there is none in the code.

Note

An em is a percentage-based measurement equal to the width of the ...

Get HTML5 24-Hour Trainer 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.