text-align
Description
text-align
sets the horizontal alignment of text.
Item | Value |
---|---|
Initial value | left if direction is ltr, and right if direction is rtl |
Inherited | Yes. |
Version | CSS1 |
JavaScript syntax | object.style.textAlign="right" |
Applies to | Block-level elements. |
Syntax and Property Values
text-align: center | justify | left | right | inherit
The property values are listed in the following table.
Value | Description |
---|---|
left | Align the text to the left |
right | Align the text to the right |
center | Center the text |
justify | justify to make line to have same width |
inherit | inherit the text-align property from the parent element |
Example
<!DOCTYPE HTML>
<html>
<head>
<style>
table {<!-- www . j av a 2 s . co m-->
width: 500px;
}
td.leftAlign {
text-align: left;
}
td.rightAlign {
text-align: right;
}
td.center {
text-align: center;
}
td.justify {
text-align: justify;
}
</style>
</head>
<body>
<table>
<tr><td class="leftAlign">Here is some text</td></tr>
<tr><td class="rightAlign">Here is some text</td></tr>
<tr><td class="center">Here is some text</td></tr>
<tr><td class="justify">Here is some text</td></tr>
</table>
</body>
</html>
The code above generates the following result.