CSS text-align
- type
- property
- applies to
- block containers — it aligns the inline content inside them
- inherits
- yes
- common values
- left (default), center, right, justify
Where it goes
On the box whose contents should line up. It passes down, so setting it on <body> or a section affects everything inside.
Example
h1 {
text-align: center;
}
.price {
text-align: right;
}Common mistakes
- Using it to center a block like a <div> or a card. It only moves inline content. A block centers with margin: 0 auto plus a width, or with flexbox on its parent.
- Putting it on the thing you want moved instead of its parent. text-align: center on a <span> does nothing. The <span> is the thing being lined up.
- Using justify on web text. It stretches the spaces to fill each line, which leaves ugly gaps in narrow columns.