Alignment |
The text-align property is used to set the horizontal alignment of a text. A text can be left, right, center or justified aligned. The following example shows text aligned left, center, right and justified. Left is the default when the alignment is not specified. |
text-align:left; | text-align:center; | text-align:right; | text-align:justify; |
---|---|---|---|
In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.' | In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.' | In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.' | In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.' |
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): |
To vertically align our horizontally aligned text we must apply padding to the element containing the text. Padding creates extra space within an element, while margin creates extra space around an element. |