text-indent
Sets the indentation of the first line of text in a block.
- Initial value
0- Inherited
- Yes
- Animatable
- yes, as a length or percentage
- Applies to
- block containers
- JavaScript
element.style.textIndent = "2em"
Example
#.book p + p {
text-indent: 1.5em;
margin-top: 0;
}<div class="book">
<p style="margin: 0">The first paragraph of a chapter usually has no indent.</p>
<p style="text-indent: 1.5em; margin: 0">The following paragraphs start with an indent and have no space between them, just like in books.</p>
</div>Definition and usage
#The text-indent property shifts the first line of text in a block by the given amount. This is the classic look of a paragraph in a printed book: the first line starts with an indent, and the following ones start at the edge.
A negative value creates what’s called a hanging indent: the first line sticks out to the left ahead of the rest. This is used, for example, in bibliographies.
Percentages are calculated against the width of the block. The indent only affects the first line of the block, and it isn’t repeated after a forced line break from <br>.
Syntax
#text-indent: <length> | <percentage>;Values
#Values in practice
#0
.demo { text-indent: 0; }2em
.demo { text-indent: 2em; }-1.5em
.demo { text-indent: -1.5em; padding-left: 1.5em; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- In book typography you use either an indent or space between paragraphs, rarely both at once.
- Don’t hide text with a large negative indent. The old
text-indent: -9999pxtrick hurts accessibility.
Related entries
#Spotted a mistake or missing an example? Write to us.