CSS text-indent Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The text-indent property sets empty space before lines of text in a block container, at the inline-start edge of the content box. By default that indents the first line.

It is inherited. The initial value is 0. Use a length or percentage, and optionally add hanging and/or each-line.

Note hanging / each-line need modern browsers

Length and percentage indent are universal. The hanging and each-line keywords are newer—check support before relying on them in production.

CSS Syntax

syntax.css
text-indent: <length> | <percentage> [ hanging ]? [ each-line ]? | initial | inherit;

Negative lengths are allowed (outdent). Percentages refer to the container’s inner inline size.

Property Values

ValueDescriptionTry it
<length>Fixed indent, e.g. 2em or 40px. Negative outdentsTry it
<percentage>Relative to the container’s inner inline sizeTry it
hangingIndent every line except the firstTry it
each-lineAlso indent lines after forced breaksTry it
initialResets to 0Try it
inheritTakes the parent’s indentTry it

How to Use text-indent

Apply it to a block element that wraps text, such as a paragraph.

  1. Target a block container (p, div, and similar).
  2. Set a length (2em) or percentage (10%) for a classic first-line indent.
  3. Use a negative value to outdent the first line if needed.
  4. Add hanging or each-line only when you need those behaviors and can accept newer browser support.
PieceRequired?Role
Block containerYesProperty applies to block boxes with text lines
Length or percentageYesHow far to indent (or outdent)
hangingOptionalIndent all lines except the first
each-lineOptionalAlso indent after forced line breaks

Live Preview

Change the indent on a short paragraph. Watch the first line move relative to the lines below.

Indent starts at the content box’s inline-start edge. Percentages use this box’s width.

Indent preview

The first line of this paragraph shows the indent. Later lines wrap under the normal start edge unless hanging is used.

text-indent: 2em

CSS Examples

Each snippet focuses on text-indent with only the CSS needed to study it. Use Try It Yourself for a live editor.

Example 1 — Classic First-Line Indent

Indent the first line by 2em.

CSS
<style>
  p {
    text-indent: 2em;
  }
</style>

<p>The first line is indented. The rest of the paragraph wraps normally under the left edge.</p>
Try It Yourself

How It Works

  1. Target the block. p is a block container, so indent applies.
  2. Set a length. 2em adds space before the first line only.
  3. Later lines. Soft-wrapped lines start at the normal inline-start edge.
  4. Inherited. Nested blocks can pick up the same indent unless overridden.

Example 2 — Percentage of the Box

Indent relative to the container’s content width.

CSS
<style>
  p {
    text-indent: 15%;
  }
</style>

<p>Fifteen percent of this paragraph box is empty before the first line of text begins.</p>
Try It Yourself

How It Works

  1. Use a percentage. 15% is based on the block’s inner inline size.
  2. Resize the box. Wider containers make a larger indent.
  3. Padding excluded. Border and padding do not count in that percentage base.
  4. Same first-line rule. Only the first line moves unless keywords change that.

Example 3 — Hanging Indent

Keep the first line flush and indent every line after it.

CSS
<style>
  p {
    text-indent: 2em hanging;
  }
</style>

<p>First line stays left. Following lines are pushed in by 2em when hanging is supported.</p>
Try It Yourself

How It Works

  1. Keep a positive length. 2em is the indent distance.
  2. Add hanging. That inverts which lines get indented.
  3. First line stays put. All other lines move inward.
  4. Check support. Older browsers may ignore the keyword and only apply 2em to the first line.

Edge Cases & Pitfalls

If the indent looks wrong, one of these is usually why.

block

Applies to block containers

Inline elements do not create the lines that text-indent targets. Use it on block-level boxes.

%

Percentages use content width

The base is the container’s inner inline size. Padding and border are excluded.

negative

Negative ≠ hanging

A negative value outdents the first line. hanging leaves the first line and indents the rest.

keywords

hanging / each-line are newer

Without support, browsers may fall back to a plain length indent on the first line only.

margin

Not the same as margin or padding

Those shift the whole box. text-indent only shifts text lines inside the content box.

Browser Support

text-indent is a browser layout property. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Length/% universal

text-indent

Length and percentage values work everywhere. hanging and each-line need modern browsers (Safari 15+, Firefox 121+, recent Chromium).

99% Length &amp; percentage
Google Chrome All / 146+ keywords
Full
Mozilla Firefox All / 121+ keywords
Full
Apple Safari All / 15+ keywords
Full
Microsoft Edge All / 146+ keywords
Full
Opera All / 131+ keywords
Full
Samsung Internet Length/%
Partial
Internet Explorer Length/%
Partial
text-indent Widely supported

Bottom line: Safe for classic first-line indents everywhere. Treat hanging and each-line as progressive enhancement.

Key Takeaways

  • Role: add empty space before text lines at the inline-start edge.
  • Common values: 2em, 40px, or a percentage of the content width.
  • Initial value: 0. Inherited. Applies to block containers.
  • Keywords: hanging and each-line are optional and newer.

One line: text-indent is the classic first-line paragraph indent—with optional hanging and each-line modes.

Frequently Asked Questions

It sets empty space before lines of text in a block container, at the inline-start edge. By default that means indenting the first line.
The initial value is 0, so no indentation is applied.
A percentage is relative to the block container's inner inline size (the content width), not including padding or border.
A negative length outdents the first line into the padding or beyond. hanging keeps the first line flush and indents every other line instead.
each-line indents the first line and each line after a forced break (like a line feed). Soft-wrapped lines are not indented again.
Length and percentage indent are supported in all major browsers, including Internet Explorer. The hanging and each-line keywords are newer and need modern browsers. It is a browser layout property, not a Node.js feature.

Next: text-justify

Learn how justified text chooses spacing between words and letters.

text-justify tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful