Indent the text of a paragraph with CSS

The text-indent property is used to indent the first line of text in a paragraph or block-level element. This creates a traditional paragraph indentation effect commonly seen in books and formal documents.

Syntax

text-indent: value;

Possible Values

  • Length units: px, em, rem, cm, mm, in, pt
  • Percentage: % (relative to parent element's width)
  • Keywords: inherit, initial, unset

Example: Basic Text Indentation

Here's how to implement text indentation using different measurement units:

<!DOCTYPE html>
<html>
<head>
    <style>
        .indent-cm {
            text-indent: 2cm;
            margin-bottom: 20px;
        }
        .indent-px {
            text-indent: 50px;
            margin-bottom: 20px;
        }
        .indent-percent {
            text-indent: 10%;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <p class="indent-cm">
        This paragraph has its first line indented by 2cm. Notice how only the first line is affected while subsequent lines align with the normal margin.
    </p>
    
    <p class="indent-px">
        This paragraph uses 50px indentation. The text-indent property only affects the first line of each paragraph or block element.
    </p>
    
    <p class="indent-percent">
        This paragraph uses 10% indentation relative to its container width. Percentage values are responsive to container size changes.
    </p>
</body>
</html>

Negative Indentation

You can also use negative values to create a hanging indent effect:

<!DOCTYPE html>
<html>
<head>
    <style>
        .hanging-indent {
            text-indent: -30px;
            padding-left: 30px;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <p class="hanging-indent">
        ? This creates a hanging indent where the first line extends beyond the left margin of subsequent lines. This technique is commonly used for bulleted lists or bibliographies.
    </p>
</body>
</html>

Comparison of Units

Unit Description Use Case
px Fixed pixel value Precise control
em Relative to font size Scalable with text
% Relative to container width Responsive layouts
cm/in Physical measurements Print stylesheets

Browser Compatibility

The text-indent property is supported by all modern browsers and has excellent compatibility across different platforms.

Conclusion

The text-indent property provides an easy way to create professional paragraph formatting. Use positive values for traditional indentation or negative values for hanging indents in lists and citations.

Updated on: 2026-03-15T23:18:59+05:30

310 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements