CSS text-indent Property
The CSS text-indent property specifies the indentation applied to the first formatted line of text in a block container.
It is commonly used to indent the opening line of a paragraph, create hanging indents, and control text alignment in documents. Indentation can be expressed using lengths, percentages, or additional keywords that modify which lines are indented.
Unlike padding-left or margin-left, text-indent affects text line positioning rather than moving the entire element or its content area.
text-indent Syntax
The property accepts a CSS length or percentage. The optional hanging and each-line keywords modify which lines receive indentation.
Basic Syntax
p {
text-indent: 2em;
}
Available Values
.example {
text-indent: 0;
}
.example {
text-indent: 30px;
}
.example {
text-indent: 2em;
}
.example {
text-indent: 3rem;
}
.example {
text-indent: 10%;
}
.example {
text-indent: -20px;
}
.example {
text-indent: 2em hanging;
}
.example {
text-indent: 2em each-line;
}
.example {
text-indent: 2em hanging each-line;
}
CSS-Wide Keywords
.example {
text-indent: initial;
}
.example {
text-indent: inherit;
}
.example {
text-indent: unset;
}
.example {
text-indent: revert;
}
.example {
text-indent: revert-layer;
}
The initial value is 0. Because text-indent is inherited, unset behaves like inherit.
Valid Examples
.example {
text-indent: 1.5em;
}
.example {
text-indent: -2rem;
}
.example {
text-indent: 15%;
}
.example {
text-indent: calc(1em + 10px);
}
.example {
text-indent: 3em hanging;
}
Invalid Examples
.example {
text-indent: auto;
}
.example {
text-indent: center;
}
.example {
text-indent: 20;
}
.example {
text-indent: 2em 3em;
}
.example {
text-indent: hanging;
}
Nonzero lengths require units, and the optional keywords must be accompanied by a length or percentage.
Property Values
| Value | Description |
|---|---|
<length> |
Specifies a fixed or font-relative indentation using units such as px, em, or rem. |
<percentage> |
Specifies indentation as a percentage of the containing block's logical width. |
hanging |
Reverses which lines receive indentation, leaving the first line unindented and indenting subsequent lines. |
each-line |
Applies indentation to the first line and lines following forced line breaks, but not ordinary automatic wraps. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | 0 |
| Inherited | Yes |
| Applies to | Block containers |
| Computed value | Absolute length, percentage, and specified keywords |
| Animation type | By computed value type |
| Percentages | Relative to the containing block's logical width |
| Negative values | Allowed |
| Specification | CSS Text Module Level 3 |
Note: The hanging and each-line keywords are defined in CSS Text Level 3, but browser support is less consistent than for basic length and percentage indentation.
How It Works
By default, text-indent moves the beginning of the first formatted line inward from the inline-start edge of the text container.
Step 1: Create a Paragraph
<p class="indented">
This paragraph demonstrates how the first line can
begin farther inward than the remaining lines.
</p>
Step 2: Add Indentation
.indented {
text-indent: 40px;
}
The first formatted line begins 40 pixels inward. Automatically wrapped lines begin at the normal inline-start edge.
Step 3: Use Font-Relative Units
.indented {
text-indent: 2em;
}
The indentation is twice the element's computed font size.
Step 4: Use a Percentage
.indented {
text-indent: 10%;
}
The indentation depends on the containing block's logical width.
Step 5: Remove Indentation
.indented {
text-indent: 0;
}
The first line returns to its normal starting position.
Important Consideration
Indentation does not add padding to the element. A large positive or negative indent can cause text to overflow its available line space.
Length Values
Length values provide direct control over the amount of indentation.
Pixels
p {
text-indent: 32px;
}
Indents the first line by 32 CSS pixels.
em Units
p {
text-indent: 2em;
}
The indentation scales with the paragraph's font size. At a font size of 16 pixels, 2em equals 32 pixels.
rem Units
p {
text-indent: 2rem;
}
The indentation is based on the root element's font size.
Character Units
p {
text-indent: 2ch;
}
The ch unit is based on the advance measure of the "0" character in the selected font.
Calculated Lengths
p {
text-indent: calc(1em + 8px);
}
The browser combines the font-relative and fixed lengths.
Choosing a Unit
Use em when indentation should scale with the paragraph's font size, rem for root-relative consistency, and px when a fixed CSS pixel measurement is appropriate.
Percentage Values
Percentage indentation is calculated relative to the containing block's logical width, which is its width in horizontal writing modes.
Basic Percentage
p {
text-indent: 10%;
}
Percentage Calculation
If the containing block is 400 pixels wide, 10% produces a 40-pixel indentation.
Responsive Indentation
.responsive-paragraph {
text-indent: 5%;
}
The indentation changes as the containing block's logical width changes.
Percentage With calc()
.example {
text-indent: calc(5% + 10px);
}
This combines a percentage of the containing block's logical width with a fixed length.
Important Consideration
Percentages are not calculated from the paragraph's font size. Use em for font-relative indentation.
Negative Indentation
Negative values move the beginning of the affected line outward toward the inline-start side of the container.
Basic Negative Indent
p {
text-indent: -20px;
}
The first line begins 20 pixels before its normal starting position.
Creating Space for a Hanging Label
.labeled-paragraph {
padding-inline-start: 2em;
text-indent: -2em;
}
The first line moves back into the padded area while wrapped lines remain indented.
Negative em Value
.example {
text-indent: -1.5em;
}
Avoiding Clipping
Negative indentation can push text outside its container. Use appropriate padding or layout space so the beginning of the line remains visible.
Important Consideration
A negative first-line indent is not the same as the hanging keyword. The keyword changes which lines receive indentation, while a negative value changes the direction of the indentation.
Hanging Indentation
A hanging indent leaves the first line at its normal starting position and indents subsequent lines.
Using the hanging Keyword
.hanging-paragraph {
text-indent: 2em hanging;
}
With supporting browsers, the first line remains unindented and subsequent lines receive a 2em indentation.
Using a Percentage
.hanging-paragraph {
text-indent: 8% hanging;
}
Alternative With Padding
.hanging-paragraph {
padding-inline-start: 2em;
text-indent: -2em;
}
This widely supported technique creates a hanging indent without relying on the hanging keyword.
HTML Example
<p class="hanging-paragraph">
Reference: This is a longer entry that wraps onto
additional lines while keeping those lines indented.
</p>
When Hanging Indents Are Useful
Hanging indents are useful for bibliographies, reference entries, definitions, and text containing labels followed by longer descriptions.
Browser Compatibility
The hanging keyword is not as consistently supported as standard length values. For production layouts that require predictable results, the padding and negative indentation technique is generally safer.
The each-line Keyword
The each-line keyword extends indentation to lines following forced line breaks, while leaving ordinary automatically wrapped lines unaffected.
Basic Syntax
.example {
text-indent: 2em each-line;
}
HTML Example
<p class="example">
First line of text.<br>
Second line after a forced break.
</p>
With support for each-line, both the first line and the line following the <br> receive indentation.
Combining each-line and hanging
.example {
text-indent: 2em hanging each-line;
}
The combination reverses which lines are indented: the first line and lines immediately following forced breaks are excluded, while other lines are indented.
Keyword Order
.example {
text-indent: 2em each-line hanging;
}
The two optional keywords can appear in either order.
Important Consideration
The each-line keyword has limited browser support. Use feature detection and test the result before relying on it in a production design.
Writing Direction
Text indentation follows the inline-start direction of the writing mode rather than always moving text from the physical left edge.
Left-to-Right Text
.ltr-text {
direction: ltr;
text-indent: 2em;
}
The first line is indented from the left side in horizontal left-to-right writing.
Right-to-Left Text
.rtl-text {
direction: rtl;
text-indent: 2em;
}
The first line is indented from the right side in horizontal right-to-left writing.
Vertical Writing
.vertical-text {
writing-mode: vertical-rl;
text-indent: 2em;
}
In vertical writing, the indentation applies along the vertical inline direction.
HTML Language and Direction
<p lang="ar" dir="rtl" class="rtl-text">
نص عربي مع مسافة بادئة في بداية السطر.
</p>
Use appropriate language and direction attributes for multilingual content rather than changing direction solely to move indentation.
Indentation vs. Spacing
The text-indent, padding-inline-start, and margin-inline-start properties affect different parts of the layout.
text-indent
p {
text-indent: 2em;
}
Moves the beginning of the first formatted line inward without shifting the entire paragraph.
padding-inline-start
p {
padding-inline-start: 2em;
}
Adds space inside the element on the inline-start side, affecting the available area for all lines.
margin-inline-start
p {
margin-inline-start: 2em;
}
Adds space outside the element on its inline-start side.
Comparison
| Property | Primary Effect |
|---|---|
text-indent |
Indents selected text lines. |
padding-inline-start |
Adds internal space along the inline-start edge. |
margin-inline-start |
Adds external space along the inline-start edge. |
Combining Indentation and Padding
.hanging-example {
padding-inline-start: 2em;
text-indent: -2em;
}
This combination creates a hanging indent using widely supported CSS.
Inheritance
The text-indent property is inherited. Descendant block containers can receive the computed indentation value from their parent.
Inherited Indentation
.article-content {
text-indent: 2em;
}
Paragraphs inside the container can inherit the indentation.
Overriding Indentation
.article-content {
text-indent: 2em;
}
.article-content .no-indent {
text-indent: 0;
}
Explicit Inheritance
.child {
text-indent: inherit;
}
Restoring the Initial Value
.child {
text-indent: initial;
}
This resets the indentation to 0.
Using unset
.child {
text-indent: unset;
}
Because the property is inherited, unset uses the parent's computed value.
Inherited Lengths and Percentages
An inherited computed length retains its length value. An inherited percentage remains a percentage and is resolved relative to the containing block of the element where it is used.
Important Consideration
Apply indentation to the intended paragraph elements when possible. Broad inheritance can produce unwanted indentation in nested content or other block containers.
Practical Examples
Traditional Paragraph Indentation
article p {
text-indent: 2em;
}
Indents the first line of each paragraph.
No Indentation
p {
text-indent: 0;
}
Fixed Pixel Indentation
.intro-paragraph {
text-indent: 36px;
}
Responsive Percentage Indentation
.responsive-paragraph {
text-indent: 5%;
}
Font-Relative Indentation
.reading-content p {
text-indent: 1.5em;
}
Hanging Reference Entry
.reference-entry {
padding-inline-start: 2em;
text-indent: -2em;
}
Hanging Keyword
.reference-entry {
text-indent: 2em hanging;
}
Use this form only when the required browsers support the hanging keyword.
Indenting Forced Line Breaks
.formatted-text {
text-indent: 2em each-line;
}
Right-to-Left Indentation
.rtl-paragraph {
direction: rtl;
text-indent: 2em;
}
Calculated Indentation
.calculated-indent {
text-indent: calc(1em + 12px);
}
Removing Indentation From the First Paragraph
article p {
text-indent: 2em;
}
article p:first-of-type {
text-indent: 0;
}
This creates a common editorial layout where the opening paragraph is flush with the text edge and later paragraphs are indented.
text-indent Example
This example compares paragraphs with no indentation, a fixed pixel indent, a font-relative indent, a percentage indent, and a hanging indent.
HTML Example
<div class="text-indent-demo">
<div class="indent-sample">
<strong>No Indentation</strong>
<p class="indent-none">This paragraph begins at the normal text edge. Additional words allow the paragraph to wrap onto another line for comparison.</p>
</div>
<div class="indent-sample">
<strong>40px Indentation</strong>
<p class="indent-pixels">This paragraph begins with a 40-pixel first-line indent. Additional words allow the paragraph to wrap onto another line for comparison.</p>
</div>
<div class="indent-sample">
<strong>2em Indentation</strong>
<p class="indent-em">This paragraph uses a font-relative first-line indent. Additional words allow the paragraph to wrap onto another line for comparison.</p>
</div>
<div class="indent-sample">
<strong>10% Indentation</strong>
<p class="indent-percent">This paragraph uses percentage-based indentation. Additional words allow the paragraph to wrap onto another line for comparison.</p>
</div>
<div class="indent-sample">
<strong>Hanging Indentation</strong>
<p class="indent-hanging">Reference: This paragraph demonstrates a hanging indent where the first line begins normally and wrapped lines are indented.</p>
</div>
</div>
CSS Example
.text-indent-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 16px;
}
.text-indent-demo .indent-sample {
padding: 18px;
border: 1px solid #cbd5e1;
background: #f8fafc;
}
.text-indent-demo strong {
display: block;
margin-bottom: 12px;
color: #334155;
font-size: 14px;
}
.text-indent-demo p {
margin: 0;
color: #1f2937;
font-size: 16px;
line-height: 1.7;
}
.text-indent-demo .indent-none {
text-indent: 0;
}
.text-indent-demo .indent-pixels {
text-indent: 40px;
}
.text-indent-demo .indent-em {
text-indent: 2em;
}
.text-indent-demo .indent-percent {
text-indent: 10%;
}
.text-indent-demo .indent-hanging {
padding-inline-start: 2em;
text-indent: -2em;
}
This paragraph begins at the normal text edge. Additional words allow the paragraph to wrap onto another line for comparison.
This paragraph begins with a 40-pixel first-line indent. Additional words allow the paragraph to wrap onto another line for comparison.
This paragraph uses a font-relative first-line indent. Additional words allow the paragraph to wrap onto another line for comparison.
This paragraph uses percentage-based indentation. Additional words allow the paragraph to wrap onto another line for comparison.
Reference: This paragraph demonstrates a hanging indent where the first line begins normally and wrapped lines are indented.
Comparing the Results
| Setting | Expected Appearance |
|---|---|
0 |
The first line starts at the normal text edge. |
40px |
The first line begins 40 pixels inward. |
2em |
The first line begins two font-size units inward. |
10% |
The first-line indentation is relative to the containing block's logical width. |
| Negative indent with padding | The first line begins at the normal edge, while wrapped lines are indented. |
Changing the Indentation
.text-indent-demo .indent-em {
text-indent: 3em;
}
The font-relative example receives a larger first-line indent.
Using Negative Indentation
.text-indent-demo .indent-pixels {
text-indent: -10px;
}
The first line moves outward from its normal starting position and may extend into the surrounding space.
Removing the Hanging Indent
.text-indent-demo .indent-hanging {
padding-inline-start: 0;
text-indent: 0;
}
All lines return to their normal starting position.
Accessibility Considerations
Text indentation can improve readability when used consistently, but excessive indentation can make text harder to follow.
Use Moderate Indentation
Choose values that clearly distinguish paragraphs without reducing the available reading width too much.
Support Text Resizing
Font-relative units such as em allow indentation to scale with text size.
Avoid Clipping
Large negative values can move text outside its container, making it difficult to read or interact with.
Test Responsive Layouts
Verify that indentation remains appropriate on narrow screens and at higher zoom levels.
Use Semantic HTML
Indentation does not replace paragraph, list, or quotation markup. Use the appropriate HTML elements for the content.
Avoid Using Indentation to Hide Text
Moving text far outside the visible area can create accessibility and usability problems.
Respect Writing Direction
Use logical layout properties and appropriate language direction so indentation works correctly with multilingual content.
Maintain Consistent Paragraph Styling
Use a consistent indentation pattern within long-form content to help readers recognize paragraph boundaries.
Common Mistakes
Using a Unitless Nonzero Value
p {
text-indent: 20;
}
Nonzero lengths require a valid CSS unit.
Correct Length Value
p {
text-indent: 20px;
}
Using auto
p {
text-indent: auto;
}
The auto keyword is not a valid value for text-indent.
Using Alignment Keywords
p {
text-indent: center;
}
Use text-align to control text alignment.
Expecting All Lines to Be Indented
p {
text-indent: 2em;
}
By default, only the first formatted line receives indentation.
Expecting Indentation to Add Padding
The text-indent property does not create internal spacing around the entire paragraph.
Using hanging Without a Length
p {
text-indent: hanging;
}
The keyword requires a length or percentage.
Using each-line Without a Length
p {
text-indent: each-line;
}
Specify an indentation amount along with the keyword.
Assuming Full Browser Support for Optional Keywords
The hanging and each-line keywords have less consistent support than basic indentation values.
Using Large Negative Values
p {
text-indent: -500px;
}
Large negative indentation can move content outside the visible area.
Confusing Percentages With Font Size
Percentage indentation is relative to the containing block's logical width, not the text's font size.
Ignoring Inheritance
Indentation applied to a parent container may also affect descendant block containers.
Important Considerations
Keep the following points in mind when using text-indent:
- The property controls indentation of selected formatted text lines.
- The initial value is
0. - The property is inherited.
- By default, only the first formatted line is indented.
- Positive values move the line inward from the inline-start edge.
- Negative values move the line outward.
- Length values can use
px,em,rem, and other valid CSS units. - Percentage values are relative to the containing block's logical width.
- Calculated values using
calc()are supported. - The
hangingkeyword reverses which lines receive indentation. - The
each-linekeyword includes lines following forced breaks. - The optional keywords can be combined.
- Optional keyword support varies between browsers.
- Padding and negative indentation provide a widely supported hanging-indent technique.
- The property follows the writing direction of the text.
- In right-to-left horizontal writing, indentation begins at the right edge.
- In vertical writing, indentation follows the vertical inline direction.
- Indentation does not move the entire element.
- Indentation does not add padding or margins.
- Large values can cause overflow or clipping.
- Font-relative units are useful for scalable typography.
- Percentage values can change with responsive layouts.
- Use semantic HTML for paragraphs, lists, and quotations.
- Test indentation at different viewport widths and zoom levels.
- Avoid using extreme indentation values to hide content.
Browser Support
The CSS text-indent property is widely available in modern browsers, including Chrome, Edge, Firefox, and Safari. Basic length, percentage, and negative indentation values have longstanding support.
The optional hanging and each-line keywords have more limited browser support and should be tested before use.
For current compatibility information, visit Can I Use? and search for text-indent.
Basic Compatibility
p {
text-indent: 2em;
}
This standard first-line indentation works across current major browsers.
Hanging Indent Fallback
.hanging-text {
padding-inline-start: 2em;
text-indent: -2em;
}
@supports (text-indent: 2em hanging) {
.hanging-text {
padding-inline-start: 0;
text-indent: 2em hanging;
}
}
The fallback uses padding and negative indentation. Browsers recognizing the hanging syntax can use the keyword instead.
Feature Detection for each-line
@supports (text-indent: 2em each-line) {
.example {
text-indent: 2em each-line;
}
}
This checks whether the browser accepts the each-line syntax.
Testing Recommendations
Test positive and negative indentation, percentages, and any optional keywords in the browsers used by your audience. Confirm that text remains visible when containers become narrow.
Specifications
The text-indent property is defined in the CSS Text Module Level 3 specification.
CSS Text Module Level 3 - text-indent Property
The specification defines first-line indentation, percentage calculations, negative values, and the optional hanging and each-line keywords.
For additional documentation and examples, consult MDN Web Docs.
