Support0

CSS text-indent playground

Explore text-indent with controls for indenting the first line of a block, changing text direction, and trying the hanging and each-line keywords.

Ask AI

CSS text-indent playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.

BaselineLab shows text-indent on the first line of a block so you can measure the paragraph indent.
This line follows a forced break and lets you check the effect of each-line.
Enabling hanging reverses the behavior: subsequent lines are indented and the first line stays at the edge.

HTML
<p class="text-indent-sample" dir="ltr">
  BaselineLab shows text-indent on the first line of a block so you can measure the paragraph indent.<br>
  This line follows a forced break and lets you check the effect of each-line.<br>
  Enabling hanging reverses the behavior: subsequent lines are indented and the first line stays at the edge.
</p>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<p class="max-inline-xl text-lg leading-7 indent-8" dir="ltr">
  BaselineLab shows text-indent on the first line of a block so you can measure the paragraph indent.<br>
  This line follows a forced break and lets you check the effect of each-line.<br>
  Enabling hanging reverses the behavior: subsequent lines are indented and the first line stays at the edge.
</p>
CSS
.text-indent-sample {
  max-inline-size: 36rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  text-indent: 2rem;
}

Educational guide to text-indent

Give each paragraph a clear entry point

Choose which lines are indented, compare lengths and percentages, and reserve space for negative values without losing text as width changes.

Mental model

text-indent shifts the start of a line’s inline content, rather than the whole paragraph box. Without keywords it affects only the first formatted line of each block. Its initial value is 0 and it inherits; on a container it can indent every descendant paragraph.

  1. Amount

    A length or percentage sets the offset. A positive value moves into the content box; a negative one moves out towards its start edge.

  2. Logical start

    Indentation begins at the start of the line. In horizontal writing this is the left in LTR and the right in RTL; the shift is not always to the right.

  3. Affected lines

    By default, only the first. each-line adds lines after forced breaks; hanging reverses the selection. Soft wraps follow the chosen rules.

Static diagram of an indentThe amount, reading start, and selected lines are separate decisions. The browser lays out text again when the available space changes.

Lengths and percentages

em follows the element’s own font size; rem follows the root’s. px keeps a fixed CSS length without following changes to the element’s font size. A percentage resolves against the block’s own inner size along the inline axis: in these horizontal scenes, its content width, excluding padding and border. It does not measure text length or a percentage of the font.

The same entry with three references

2em

Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.

2rem

Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.

10% · max-inline-size: 32ch

Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.

10% · max-inline-size: 20ch

Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.

The samples use a 1.25rem font: 2em equals 2.5rem here, while 2rem follows the root. The last two samples use 10% and different maximum widths; if the screen makes both occupy the same width, their indents also match. The border marks the box.
The same entry with three references
<div class="text-indent-guide-units" lang="en">
  <div>
    <p class="label">2em</p>
    <p class="sample em">Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.</p>
  </div>
  <div>
    <p class="label">2rem</p>
    <p class="sample rem">Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.</p>
  </div>
  <div>
    <p class="label">10% · max-inline-size: 32ch</p>
    <p class="sample percent">Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.</p>
  </div>
  <div>
    <p class="label">10% · max-inline-size: 20ch</p>
    <p class="sample percent narrow">Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.</p>
  </div>
</div>
.text-indent-guide-units {
  display: grid;
  gap: 1rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    max-inline-size: 32ch;
    margin: 0;
    border: 1px solid currentColor;
    font-size: 1.25rem;
    line-height: 1.6;
    text-align: start;
    text-wrap: wrap;
  }

  .em {
    text-indent: 2em;
  }

  .rem {
    text-indent: 2rem;
  }

  .percent {
    text-indent: 10%;
  }

  .narrow {
    max-inline-size: 20ch;
  }
}

Choose em for an indent proportional to the typography and rem for a shared page reference. Use percentages only when the entry should change with the block’s own width. Inheritance passes the computed value: an already resolved em length does not recalculate with the child’s font, while an inherited percentage resolves in each block. Limit the selector to the text you want to indent and check narrow columns and enlarged text.

First line, each-line, and hanging

each-line distinguishes forced breaks from soft wrapping. It adds indentation after br or a newline preserved by white-space, but not after every break caused by insufficient width. hanging reverses the affected lines: alone it indents all but the first; combined with each-line it leaves the first and lines after forced breaks unindented.

One br and four line selections

2em

This first stretch contains enough words to wrap across several lines before reaching an explicit break.
After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.

2em each-line · Syntax acceptedFallback without indentation

This first stretch contains enough words to wrap across several lines before reaching an explicit break.
After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.

2em hanging · Syntax acceptedFallback without indentation

This first stretch contains enough words to wrap across several lines before reaching an explicit break.
After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.

2em hanging each-line · Syntax acceptedFallback without indentation

This first stretch contains enough words to wrap across several lines before reaching an explicit break.
After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.

2em shifts only the paragraph’s beginning; each-line also shifts the beginning after br. hanging leaves the first flush and shifts the rest, including the line after br; hanging each-line leaves both beginnings flush and shifts only their soft-wrapped continuations. Each variant checks its syntax: if unsupported it keeps 0 and says so.
One br and four line selections
<div class="text-indent-guide-lines" lang="en">
  <div class="first">
    <p class="label">2em</p>
    <p class="sample">This first stretch contains enough words to wrap across several lines before reaching an explicit break.<br>After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.</p>
  </div>
  <div class="each">
    <p class="label">2em each-line · <span class="native">Syntax accepted</span><span class="fallback">Fallback without indentation</span></p>
    <p class="sample">This first stretch contains enough words to wrap across several lines before reaching an explicit break.<br>After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.</p>
  </div>
  <div class="hanging">
    <p class="label">2em hanging · <span class="native">Syntax accepted</span><span class="fallback">Fallback without indentation</span></p>
    <p class="sample">This first stretch contains enough words to wrap across several lines before reaching an explicit break.<br>After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.</p>
  </div>
  <div class="both">
    <p class="label">2em hanging each-line · <span class="native">Syntax accepted</span><span class="fallback">Fallback without indentation</span></p>
    <p class="sample">This first stretch contains enough words to wrap across several lines before reaching an explicit break.<br>After the break another stretch of the same paragraph begins. Its lines also wrap to the available space without adding any more br elements.</p>
  </div>
</div>
.text-indent-guide-lines {
  display: grid;
  gap: 1rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    max-inline-size: 32ch;
    margin: 0;
    border: 1px solid currentColor;
    font-size: 1.25rem;
    line-height: 1.6;
    text-align: start;
    text-wrap: wrap;
  }

  .sample {
    text-indent: 0;
  }

  .first .sample {
    text-indent: 2em;
  }

  .native {
    display: none;
  }

  @supports (text-indent: 2em each-line) {
    .each {
      .sample {
        text-indent: 2em each-line;
      }

      .native {
        display: inline;
      }

      .fallback {
        display: none;
      }
    }
  }

  @supports (text-indent: 2em hanging) {
    .hanging {
      .sample {
        text-indent: 2em hanging;
      }

      .native {
        display: inline;
      }

      .fallback {
        display: none;
      }
    }
  }

  @supports (text-indent: 2em hanging each-line) {
    .both {
      .sample {
        text-indent: 2em hanging each-line;
      }

      .native {
        display: inline;
      }

      .fallback {
        display: none;
      }
    }
  }
}

These scenes use native CSS and @supports for each complete value. The label confirms syntax acceptance, not correct typesetting in every language. The fallback preserves reading without reproducing the effect. Use br when the break belongs to the content, such as verse or addresses; do not add it to fix a screenshot layout. Every p is another block with its own first line.

Negative indentation and logical space

A negative value moves the first line out of the content box. It is not equivalent to positive hanging: hanging moves other lines inward without moving the first out. For a hanging indent without that keyword, combine positive padding-inline-start with an equal negative text-indent. The inner space contains the outdent and follows the paragraph’s direction.

A hanging indent without keywords, in LTR and RTL

dir="ltr" · padding-inline-start: 1.5em · text-indent: -1.5em

Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.

dir="rtl" · padding-inline-start: 1.5em · text-indent: -1.5em

تبدأ قراءة الفقرة من اليمين وتستمر الكلمات في أسطر جديدة بحسب المساحة المتاحة. يبقى السطر الأول عند حافة الإطار وتبدأ الأسطر التالية إلى الداخل.

The first line begins next to the frame’s inner border; following lines sit 1.5em inward. padding-inline-start reserves exactly what text-indent subtracts. In Arabic RTL both act from the right; lang="ar" identifies language and dir="rtl" direction.
A hanging indent without keywords, in LTR and RTL
<div class="text-indent-guide-negative">
  <div>
    <p class="label">dir="ltr" · padding-inline-start: 1.5em · text-indent: -1.5em</p>
    <p class="sample" lang="en" dir="ltr">Reading begins with an entry that distinguishes the paragraph. As width decreases, words wrap onto new lines and the content keeps its order. Compare the start of the first line with the following ones without adding spaces to the text.</p>
  </div>
  <div>
    <p class="label">dir="rtl" · padding-inline-start: 1.5em · text-indent: -1.5em</p>
    <p class="sample" lang="ar" dir="rtl">تبدأ قراءة الفقرة من اليمين وتستمر الكلمات في أسطر جديدة بحسب المساحة المتاحة. يبقى السطر الأول عند حافة الإطار وتبدأ الأسطر التالية إلى الداخل.</p>
  </div>
</div>
.text-indent-guide-negative {
  display: grid;
  gap: 1rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    max-inline-size: 32ch;
    margin: 0;
    border: 1px solid currentColor;
    font-size: 1.25rem;
    line-height: 1.6;
    text-align: start;
    text-wrap: wrap;
  }

  .sample {
    box-sizing: border-box;
    padding-inline-start: 1.5em;
    text-indent: -1.5em;
  }
}

padding-inline-start moves the start of every line and takes up space in the box; text-indent adjusts selected lines. margin-inline-start shifts the whole box. The recipe uses box-sizing: border-box to include padding and border in its maximum width. A negative value without enough space may overflow, overlap, or be clipped by an ancestor. Do not hide overflow to fix it or use a huge indent to hide text; always check actual reflow, zoom, and direction.

Common pitfalls

The percentage changes as the column narrows

Expected result
The amount follows the chosen reference.
Cause
The percentage depends on the block’s own inner inline size, not its font or character count.
Solution
Use em or rem for a typographic reference. Do not combine large percentages and intrinsic sizes without checking overflow.

each-line does not indent every line

Expected result
Only the first line and those after forced breaks receive indentation.
Cause
Soft wraps caused by width do not count as forced breaks; an older engine may also ignore the entire declaration containing keywords.
Solution
Check br and white-space, test the syntax with @supports, and provide a readable base value. Do not insert breaks or spaces to imitate the effect.

The first word sits outside the frame

Expected result
All text keeps enough space and remains readable when enlarged.
Cause
The negative indent exceeds the space reserved at the box’s start, or a container clips the outdent.
Solution
Reserve space with padding-inline-start and use a proportionate amount. Check LTR/RTL and narrow widths without hiding text or reducing its size.

Support and compatibility

text-indent lengths and percentages have widely established support. hanging and each-line have separate, more recent compatibility: BCD records Chrome/Edge 146, Firefox 121, and Safari 15 as initial versions. The playground’s Baseline card covers the basic property and does not guarantee these keywords in older versions.

The three keyword variants start at text-indent: 0 and activate inside independent @supports queries. If a complete declaration is not understood, it is ignored: its length alone is not automatically retained. The alternative using logical padding and a negative value uses basic syntax. All comparisons are served as HTML/CSS and stay readable without JavaScript; they do not certify accessibility or every engine.