CSS Reference ยท Typography
The text-indent property
Reference for the CSS text-indent property: indenting the first line of a paragraph, negative values for hanging indents, percentages and examples.
The text-indent property sets the horizontal space before the first line of a block's text. It is the classic book-style paragraph indent. Negative values pull the first line outward, which together with padding creates a hanging indent, as used in bibliographies.
CSS
p { text-indent: 2em; }
Try it
Syntax
CSS
text-indent: <length-percentage> && [ hanging || each-line ]?;
- Initial value:
0 - Applies to: block containers
- Inherited: yes
- Animatable: yes, as a length or percentage
- Computed value: an absolute length or percentage, plus any keywords as specified
Values
| Value | Description |
|---|---|
<length> |
A fixed indent such as 2em or 24px. Negative values are allowed. |
<percentage> |
A percentage of the width of the containing block. |
each-line |
Also indents the first line after each forced line break inside the block. Limited support; check a compatibility table. |
hanging |
Inverts which lines are indented: the first line stays, all others are indented. Limited support; check a compatibility table. |
Usage notes
- Only the first line. The first formatted line of the block is affected. Block children, such as nested
<div>s, are not indented by their parent's value unless they inherit it. - It is inherited. A value set on a container is inherited by paragraphs inside and may apply to nested blocks. Reset it when needed.
- Use
em. An indent of1emto2emscales with the font size. - Hanging indent trick. Pair a negative
text-indentwith equalpadding-left(ormargin-left). If you forget the padding, the first line is pushed outside the box and can be clipped. - Inline-blocks and floats are treated like content on the first line, and the indent applies before them.
- Hiding text with a huge negative indent (
-9999px) was an old way to replace text with an image. It is bad for accessibility and is no longer needed. Use real images or visually hidden techniques. - Web style. Websites usually separate paragraphs with space instead of indents. Pick one style; using both is redundant.
Browser support
Length and percentage values work in every browser. hanging and each-line are newer; check a compatibility table.
Related
text-alignโ horizontal alignmentpaddingโ used for hanging indentsmarginโ spacing between paragraphs- Lesson: Styling Text