text-align
Example
.card {
width: 300px;
text-align: center;
}.card {
width: 300px;
margin-inline: auto;
text-align: center;
}text-align centers only the text inside; margin-inline: auto centers the card block itself.
Common mistakes
text-align: centerdoesn't center a fixed-width block, only its inline content.- Text aligned with
leftstays on the wrong side in Arabic or Hebrew pages.
Key points
- Alignment uses logical values
startandend, so text flips correctly in right-to-left languages. - Blocks are centered with
margin-inline: autoor flex/grid, nottext-align: centeron the parent. - Long body text is not
justifyaligned withouthyphens, which leaves uneven word gaps.
Interview questions
What is the difference between text-align: left and start?
left always aligns left. start aligns to the start of the line, which is the right side in right-to-left text.
How do I center text vertically?
text-align is horizontal only. Use flexbox or grid with align-items: center for vertical centering.
Is justified text bad for accessibility?
It can be: uneven word gaps make text harder to read for some people, so left or start alignment is safer for body text.