Web - Text alignment and decoration
Code Life
By Pierre Marsaa
Introduction to Text Alignment
Text alignment is one of the most basic and important aspects of text styling. In CSS, we use the text-align property to control how text is aligned within its containing element.
The text-align property can have the following values:
- left - Aligns text to the left (default)
- center - Centers the text
- right - Aligns text to the right
- justify - Stretches lines so that each line has equal width (like in newspapers)
↗️
Loading editor...
↶
↷
The text-align property is inherited, meaning that if you set it on a parent element, all child elements will inherit that alignment unless they have their own text-align property specified.
When to Use Each Alignment
- left: Best for most body text as it's easiest to read in left-to-right languages
- center: Good for headings, titles, and short pieces of text
- right: Useful for specific design elements or RTL languages
- justify: Works well for dense text in columns, but can create uneven spacing between words
Verify