πŸ“˜ CSS Tutorial: text-indent

πŸ“Œ Introduction

The text-indent property in CSS controls the indentation of the first line of text within a block-level element. It is commonly used in paragraphs, articles, books, and readable content layouts to create a clean and professional typography style. ✨

🎯 Why Use text-indent?

  • To create book-style paragraph indentation πŸ“š
  • To visually separate paragraphs without extra spacing ✍️
  • To create stylized layouts (quotes, blog posts, articles) πŸ“°
  • To push the first line for creative UI effects 🎨

🧠 What Does text-indent Do?

It shifts only the first line of text inside an element. The rest of the lines remain unchanged, creating a clean indentation effect.

✨ Syntax

Basic Syntax

selector {
  text-indent: <length> | <percentage> | hanging | each-line;
}

Note

text-indent works only on block containers (like <p>,<div>, <article>).

🧩 Available Values

1. <length>

Use units like px, em, rem, etc.

Length Example

p {
  text-indent: 40px;
}

2. <percentage>

Percentage is relative to the width of the containing block.

Percentage Example

p {
  text-indent: 10%;
}

3. negative values β›”

Negative indentation pulls the first line to the left.

Negative Example

p {
  text-indent: -20px;
}

4. hanging 🧷

Indicates that all lines except the first one should be indented β€” creating a β€œhanging indent’’ often used in lists or citations.

Hanging Example

p {
  text-indent: hanging 20px;
}

5. each-line ✨

Applies the indentation to every line in the block container except the first line of the block when text wraps.

Each-line Example

p {
  text-indent: each-line 30px;
}

πŸ”₯ Practical Examples

1. Classic Paragraph Indent

Classic Indentation

p {
  text-indent: 2em;
}

2. Blog or Magazine Style

Stylized Article Layout

article p {
  text-indent: 1.5rem;
  line-height: 1.6;
}

3. Creative Pull-Left Text

Negative Value for Creative Layouts

.pull-left {
  text-indent: -30px;
  padding-left: 30px;
}

πŸ“Š Comparison Table

ValueEffect
40pxIndents the first line by 40px
10%Indent based on container width
-20pxPulls the first line to the left
hanging 20pxAll lines except first are indented
each-line 30pxEach wrapped line gets indentation

πŸ–ΌοΈ Visual Example

>>β€œGood typography guides the reader β€” indentation is one of those subtle guides.” ✨

πŸŽ‰ Conclusion

The text-indent property is a powerful yet simple tool for controlling how your content begins visually. Whether you're designing a blog, building a reading app, or formatting stylish paragraphs, mastering text-indent brings professional polish to your layouts. πŸš€