CSS alignment text-align property
CSS Alignment text-align Property
Description
The text-align property determines the alignment of line boxes within a block-level element.
Possible Values
- left – The left edge of each line box is aligned with the left edge of the block-level element’s content area.
-
right – The right edge of each line box is aligned with the right edge of the block-level element’s content area.
-
center – The center of each line box is aligned with the center of the block-level element’s content area.
-
justify – The edges of each line box are aligned with the edges of the block-level element’s content area.
-
string – The contents of the cells in the column will be aligned according to the given string.
Applies to
All block-level elements (except the value <string>
, which only applies to table cells).
DOM Syntax
object.style.textAlign = "justify";
Example
Here is an example demonstrating how to align text –
<html>
<head>
</head>
<body>
<p style = "text-align:right;">
This will be right aligned.
</p>
<p style = "text-align:center;">
This will be center aligned.
</p>
<p style = "text-align:left;">
This will be left aligned.
</p>
</body>
</html>
This will produce the following result−