CSS text-indent Property
Description
The text-indent
CSS property is used to control the indentation of the first line of a block-level element's text content. By specifying a positive value, you can push the entire text within the element to the right, creating an indentation. This property is commonly used in paragraphs, lists, and other text-containing elements to create a consistent and visually appealing layout. Negative values can be used to create a hanging indent, where the first line is pushed to the left of the element's content box. text-indent is a helpful tool for controlling the alignment and structure of text within web page elements.
- Initial value
- 0
- Applies to
- Block containers
- Inherited
- Yes
- Computed value
- Percentage or absolute length
- Animatable
- No
- JavaScript syntax
- object.style.textIndent
Interactive Demo
Syntax
text-indent: [ <length> | <percentage> ] && hanging? && each-line?
Values
- <length>Gives the amount of the indent as an absolute length.
- <percentage>Gives the amount of the indent as a percentage of the containing block's logical width.
- each-lineIndentation 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.
- hangingInverts which lines are indented. All lines except the first line will be indented.
- inherit
Example
<p class="test">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p class="test2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p class="test3">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
.test {
text-indent: 0px;
width: 500px;
}
.test2 {
text-indent: 40px;
width: 500px;
}
.test3 {
text-indent: -20px;
width: 500px;
}
Browser Support
The following table will show you the current browser support for the CSS text-indent
property.
Desktop | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
|
12 | 1 | 1 | 3.5 | 1 |
Tablets / Mobile | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
18 | 4 | 14 | 1 | 1 | 37 |
Last updated by CSSPortal on: 2nd January 2024