π 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
<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
| Value | Effect |
|---|---|
| 40px | Indents the first line by 40px |
| 10% | Indent based on container width |
| -20px | Pulls the first line to the left |
| hanging 20px | All lines except first are indented |
| each-line 30px | Each wrapped line gets indentation |
πΌοΈ Visual Example
Further details can be found at: https://dummyimage.com/900x250/eeeeee/000000&text=text-indent+demo
π 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. π