CSS Portal

CSS text-indent Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The text-indent property controls the horizontal offset of the first formatted line of a block container. It is commonly used to create the visual effect of a paragraph indent or a hanging indent: a positive offset shifts the first line inward from the block’s starting edge, while a negative offset pulls the first line outward so subsequent lines appear indented relative to it. Because it targets the first formatted line, it does not directly change the alignment or spacing of the rest of the lines in the block; their positions are determined by the normal line box flow and other layout properties.

When using text-indent you should be aware of interactions with the document’s inline direction and whitespace handling. The effective side that counts as the “start” depends on the element’s writing direction, so behavior will follow the element’s direction. Also, the way whitespace is preserved or collapsed can affect whether the visual indent appears where you expect — settings controlled by white-space influence how initial line breaks and leading spaces interact with the indentation. When combined with horizontal alignment choices, the indent can produce different visual results; for example, combining an indent with text-align that centers or right-aligns text requires careful consideration to keep the intended layout consistent.

The property applies to elements that generate a block box (or to the first formatted line of an inline block’s content), and it can be overridden or limited by other layout factors such as padding, margins, floats, or overflow/clipping. In vertical writing modes the offset will apply along the inline-start direction appropriate for that mode, so its perceptual effect differs from horizontal left-right indents. It also plays nicely with the ::first-line conceptually—because both target first-line presentation—though the pseudo-element is used to style properties on that line rather than to move it.

From a practical standpoint, designers use text-indent for typographic niceties like paragraph indents in long-form text, first-paragraph suppression in headings or lead paragraphs, and hanging indents for lists or citations. Be cautious with large negative offsets because they can push text outside the visible area or make content difficult to select or read, which can have accessibility and usability consequences. When precise layout is required across different writing modes and browsers, test how the indentation interacts with other layout settings (margins, padding, floats, overflow) to ensure the visual result matches your intent.

Definition

Initial value
0
Applies to
Block containers
Inherited
Yes
Computed value
Percentage or absolute length
Animatable
No
JavaScript syntax
object.style.textIndent

Interactive Demo

The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff. Somewhere, beyond the veil of dusk, a coyote laughed, echoing through the stillness like a forgotten memory.

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

<body>
<div class="container">
<h1>CSS text-indent examples</h1>

<p class="default">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae lacus nec nisl tincidunt consectetur. Curabitur sit amet urna sed justo pharetra convallis.</p>

<p class="indent">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae lacus nec nisl tincidunt consectetur. Curabitur sit amet urna sed justo pharetra convallis.</p>

<p class="first-line">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae lacus nec nisl tincidunt consectetur. Curabitur sit amet urna sed justo pharetra convallis.</p>

<p class="hanging">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae lacus nec nisl tincidunt consectetur. Curabitur sit amet urna sed justo pharetra convallis.</p>

<p class="percent">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae lacus nec nisl tincidunt consectetur. Curabitur sit amet urna sed justo pharetra convallis.</p>
</div>
</body>
body {
  font-family: Arial, sans-serif;
  padding: 2rem;
  line-height: 1.6;
  background: #f5f7fa;
  color: #222;
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

h1 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

p {
  margin: 0 0 1rem 0;
}

/* Indent the first line by 2em */
.indent {
  text-indent: 2em;
}

/* Apply text-indent to the first formatted line only */
p.first-line::first-line {
  text-indent: 3em;
  font-weight: 600;
}

/* Hanging indent: negative text-indent and matching left padding */
.hanging {
  text-indent: -1.5em;
  padding-left: 1.5em;
}

/* Percentage-based text indent */
.percent {
  text-indent: 10%;
}

Browser Support

The following information will show you the current browser support for the CSS text-indent property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!