# text-align

> The `text-align` CSS property specifies the alignment of text content within an element's box.

## How do I center text horizontally in CSS?

The property that sets the horizontal alignment of text within an element. It can be aligned to the left, right, center or justified, controlling how text flows in relation to the container's edges, making it crucial for creating visually balanced typography.

- Topic: Text Handling
- Type: property
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 1+, Safari iOS 1+

## Example

Wrong:

```css
.card {
  width: 300px;
  text-align: center;
}
```

Right:

```css
.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: center` doesn't center a fixed-width block, only its inline content.
- Text aligned with `left` stays on the wrong side in Arabic or Hebrew pages.

## Key points

- Alignment uses logical values `start` and `end`, so text flips correctly in right-to-left languages.
- Blocks are centered with `margin-inline: auto` or flex/grid, not `text-align: center` on the parent.
- Long body text is not `justify` aligned without `hyphens`, 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.

## Related cards

- [Logical Properties](https://wonderium.dev/css/logical-properties.md)
- [align-items](https://wonderium.dev/css/align-items.md)
- [margin](https://wonderium.dev/css/margin.md)
- [hyphens](https://wonderium.dev/css/hyphens.md)
- [RTL](https://wonderium.dev/web/rtl.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/text-align
- Last updated: 2026-11-25
