W3cubDocs

/CSS

text-indent

The text-indent CSS property specifies the amount of indentation (empty space) that is put before lines of text in a block. By default, this controls the indentation of only the first formatted line of the block, but the hanging and each-line keywords can be used to change this behavior.

/* <length> values */
text-indent: 3mm;
text-indent: 40px;

/* <percentage> value
   relative to the containing block width */
text-indent: 15%;

/* Keyword values */
text-indent: 5em each-line;
text-indent: 5em hanging;
text-indent: 5em hanging each-line;

/* Global values */
text-indent: inherit;
text-indent: initial;
text-indent: unset;

Horizontal spacing is with respect to the left (or right, for right-to-left layout) edge of the containing block-level element's content box.

Initial value 0
Applies to block containers
Inherited yes
Percentages refer to the width of the containing block
Media visual
Computed value the percentage as specified or the absolute length, plus any keywords as specified
Animation type a length, percentage or calc();
Canonical order The length or percentage before the keywords, if both are present. If several keywords are present, they appear in the same order as their appearance in the formal grammar.

Syntax

Values

<length>
Indentation is specified as an absolute <length>. Negative values are allowed. See <length> values for possible units.
<percentage>
Indentation is a <percentage> of the containing block's width.
each-line
Indentation affects the first line of the block container as well as each line after a forced line break, but does not affect lines after a soft wrap break.
hanging
Inverts which lines are indented. All lines except the first line will be indented.

Formal syntax

<length-percentage> && hanging? && each-line?

where
<length-percentage> = <length> | <percentage>

Simple indent example

HTML

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 
    nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 
    nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>

CSS

p { 
  text-indent: 5em;
  background: powderblue;
}

Percentage indent example

HTML

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 
    nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 
    nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>

CSS

p { 
  text-indent: 30%;
  background: plum;
}

Specifications

Specification Status Comment
CSS Text Module Level 3
The definition of 'text-indent' in that specification.
Working Draft Adds the hanging and each-line keywords.
CSS Transitions
The definition of 'text-indent' in that specification.
Working Draft Lists text-indent as animatable.
CSS Level 2 (Revision 1)
The definition of 'text-indent' in that specification.
Recommendation The behavior with display: inline-block and anonymous block boxes is explicitly defined.
CSS Level 1
The definition of 'text-indent' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 1 Yes 1 3 3.5 1
each-line No No No No No No
hanging No No No No No No
Feature Android webview Chrome for Android Edge mobile Firefox for Android IE mobile Opera Android iOS Safari
Basic support Yes Yes Yes 4 Yes Yes Yes
each-line No No No No No No No
hanging No No No No No No No

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent