Text Alignment



Text alignment is the ability to arrange a block of text such as a heading or a paragraph so that it is aligned against the left margin (left justifiction, the default), aligned against the right margin (right justification), or centered.

Aligning Individual Elements

To align an individual heading or paragraph, use the ALIGN attribute to the HTML element. Align has one of three values: LEFT, RIGHT, or CENTERED. Here are some examples:

<H1 ALIGN=CENTER> This header will be centered on the page</H1>

<P ALIGN=CENTER> This paragraph will be centered.

<H1 ALIGN=LEFT> This header will be left justified

<H2 ALIGN=RIGHT> This header will be right justified

NOTE:Browsers support this type of alignment to varying degrees.

Aligning Blocks of Elements

A slightly more flexible method of aligning text elements is to use the <DIV> tag. <DIV> stands for division, and includes the ALIGN attribute just as headings and paragraphs do. Unlike the alignments in individual elements, <DIV> is used to surround a block of HTML tags of any kind, and it affects all the tags and text inside the opening and closing tags. There are two advantages of <DIV>: