back next

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 justification, the default), aligned against the right margin (right justification), or centered.

1. To align an individual heading or paragraph, use the align attibute to the HTML element. align has on the 3 values: left, right, or center .

Example
<html>
<head> <title>HTML Tutor</title>
</head><body>
<h1 align=center> Hello world! </h1>
<p align=right> By..Neon </p>
</body>
</html>


Output


2. A method of aligning text elements is to use the <div> tag.

Example 2
<html>
<head> <title>HTML Tutor</title>
</head><body>
<div align=right>
<h1> Hello world ! </h1>
<h2> Hello world ! </h2>
<h3> Hello world ! </h3>
</body>
</html>


Output


In addition to <div>, there is also the centering tag <center>. The <center> tag acts indentically to <div align=center>

<center>
<h1>Hello World ! </h1>
<h2>Hello World ! </h2>
</center>



Back to HTML tutor homepage | Back | Next | Email me