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.
- 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.
- 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.
- Affected lines
By default, only the first. each-line adds lines after forced breaks; hanging reverses the selection. Soft wraps follow the chosen rules.
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.
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.
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
تبدأ قراءة الفقرة من اليمين وتستمر الكلمات في أسطر جديدة بحسب المساحة المتاحة. يبقى السطر الأول عند حافة الإطار وتبدأ الأسطر التالية إلى الداخل.
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.