CSS Text Alignment
CSS Text Alignment and Text Direction
Text Alignment
The text-align property is used to set the horizontal alignment of a text.
This property can have one of the following values:
left- Aligns the text to the leftright- Aligns the text to the rightcenter- Centers the textjustify- Stretches the lines so that each line has equal width
When the text-align property is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers):
Example
div {
text-align: justify;
}
Text Align Last
The text-align-last property specifies how to align the last line of a text.
This property can have one of the following values:
auto- Default value. The last line is justified and aligned leftleft- The last line is aligned to the leftright- The last line is aligned to the rightcenter- The last line is center-alignedjustify- The last line is justified as the rest of the linesstart- The last line is aligned at the start of the lineend- The last line is aligned at the end of the line
Example
Different alignment of the last line in three <p> elements:
p.a {
text-align-last: right;
}
p.b {
text-align-last: center;
}
p.c {
text-align-last: justify;
}
Vertical Alignment
The vertical-align property sets the vertical alignment of an element.
This property can have one of the following values:
baseline- Default value. The element is aligned with the baseline of the parentlength/%- Raises or lower an element by the specified length or percentsub- The element is aligned with the subscript baseline of the parentsuper- The element is aligned with the superscript baseline of the parenttop- The element is aligned with the top of the tallest element on the linetext-top- The element is aligned with the top of the parent element's fontmiddle- The element is placed in the middle of the parent elementbottom- The element is aligned with the lowest element on the linetext-bottom- The element is aligned with the bottom of the parent element's font