Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

P - normal paragraph

Purpose

To present a normal text paragraph.

Typical rendering

As a text paragraph, suitably separated (normally with some extra white space such as an empty line) from other paragraphs, headings etc. A browser might leave some extra space at the beginning of the first line; most browsers don't.

Browsers usually format paragraphs to fit into the horizontal space (screen or window width) available.

Paragraphs are usually rendered flush left with a ragged right margin. The ALIGN attribute can be used to specify explicitly the horizontal alignment.

Basic syntax

<P>paragraph text</P>

Possible attributes (Not in HTML 2.0!)

attribute name possible values meaning notes
ALIGN LEFT, CENTER, RIGHT alignment of the paragraph (flush left, centered, flush right) deprecated in HTML 4.0

The default is left alignment, but this can be overridden by an enclosing DIV (or CENTER) element.

Allowed context

Block container.

Contents

Text elements.

Examples

A normal example:

Example P-1.html:

<P>
This is a normal text paragraph which contains so many characters
that it will most probably be split into several lines by a browser.
</P>
A contrived example:

Example P-2.html:

<P>
This is a normal text paragraph with no attribute for horizontal
alignment. Nothing special.
</P>
<P ALIGN=CENTER>
<B>This is a paragraph which should be centered. It should also appear
in bold face but this results from explicit use of a B element.
Centering itself should not affect the font.</B>
</P>
<P ALIGN=RIGHT>
This is a paragraph which should be rendered flush right. It is difficult
to see why you would ever <EM>like</EM> to use this option!
</P>
See also the examples about BLOCKQUOTE, one of which makes reasonable use of ALIGN=RIGHT.

Notes

See the general discussion of paragraph-like elements for selecting a suitable HTML element for different kinds of paragraphs. In particular, if you have a collection of closely related small paragraphs, you may wish to consider making them into a list using UL and LI instead of P; this typically results in more compact presentation visually.

If you intend to use P for alignment purposes, such as centering text, remember that a P element may only contain text elements. The DIV element may contain block elements, too.

There is no way in HTML (in HTML 3.2 at least) to make text appear "justified" (solid-right), unless you want to resort to using the PRE element. More exactly, such presentation issues are browser-dependent, and the great majority of browsers use ragged right margin.

The end tag </P> can always be omitted, and it usually is omitted. It is, however, advisable to use explicit </P> tags for the following reasons:

One reason for regarding <P> as paragraph separator is that it was defined that way in an early HTML draft; notice that no approved HTML specification ever defined <P> that way.

Paragraphs cannot be nested. (This is the other side of the "nice" feature that </P> can be omitted.) One way of simulating subparagraphs is to use BR elements around a piece of text within a P element. Another way is to use list elements (such as UL) instead of P elements.

The division into lines in the rendering usually does not match the HTML source. See the section Division into lines and the use of blanks and tabs.



Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.