text-indent

Term side of the Card.
Topic: Text Handling
Unit title: text-indent
Categories: Property
Explanation side of the Card

Explanation: The property that specifies the amount of space that is added before the start of the first line of text in a block. It's commonly used to indent the first line of a paragraph, making text easier to read or helping to visually separate content.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wrongcss
.intro span {
  text-indent: 2em;
}
Rightcss
.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-indent on a span and seeing no change.
  • Using a large negative indent to hide text, which breaks in right-to-left layouts.

Key points

  • text-indent is set on a block container such as p, not on an inline span.
  • Indents use em so 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'.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy