HTML and CSS Reference
In-Depth Information
Text Alignment
Text alignment is the capability to arrange a block of text, such as a heading or a para-
graph, so that it's aligned against the left margin (left justification, the default), aligned
against the right margin (right justification), or centered. The old-fashioned approach to
aligning elements is to use the align attribute, which was deprecated as of HTML 4.01
and has been removed completely from HTML5. The approach currently in favor is to
use CSS, as explained next.
Aligning Individual Elements
To align an individual heading or paragraph, include the align attribute in the opening
tag. The align attribute has four values: left , right , center , and justify . Consider the
following examples in the code snippet that follows.
The following input and output example shows the simple alignment of several headings.
Figure 7.13 shows the results.
<h1 align=”center”> Northridge Paints, Inc. </h1>
<p align=”center”> We don't just paint the town red. </p>
<h1 align=”left”> Serendipity Products </h1>
<h2 align=”right”><a href=”who.html”> Who We Are </a></h2>
<h2 align=”right”><a href=”products.html”> What We Do </a></h2>
<h2 align=”right”><a href=”contacts.html”> How To Reach Us </a></h2>
with varying
Aligning Blocks of Elements
A slightly more flexible method of aligning text elements is to use the <div> tag. The
<div> tag supports several attributes. Among these attributes is align (deprecated as
of HTML 4.01), which aligns elements to the left, right, or center just as it does for
Search WWH ::

Custom Search