text-indent
Example
.intro span {
text-indent: 2em;
}.intro {
text-indent: 2em;
}text-indent only applies to block containers, so it belongs on the paragraph, not on an inline element inside it.
Common mistakes
- Putting
text-indenton aspanand seeing no change. - Using a large negative indent to hide text, which breaks in right-to-left layouts.
Key points
text-indentis set on a block container such asp, not on an inlinespan.- Indents use
emso they scale with the font size. - Hiding text uses a visually hidden class, not
text-indent: -9999px.
Interview questions
How do I make a hanging indent in CSS?
Use a negative text-indent with the same positive padding-inline-start, so the first line starts left of the rest.
Does text-indent apply to every line?
No. By default it indents only the first line of the block, and lines after a forced break are not indented.
Why does text-indent not work on my span?
Inline elements are not block containers. Set the property on the parent block or make the element display: block or 'inline-block'.