π Introduction
The text-underline-offset property in CSS allows you to adjust the vertical distance between the text and its underline. It is extremely useful when you want more precise control over typography, especially for modern UI, headlines, or link designs. β¨
π§ What Does text-underline-offset Do?
This property changes how far the underline appears from the baseline of the text. A positive value pushes the underline downward (further away). A negative value (rarely needed) brings it closer or even inside the text.
β¨ Syntax
Basic Syntax
text-underline-offset: auto | <length> | <percentage>;π Values Explained
| Value | Description |
|---|---|
| auto | Browser sets default underline position |
| length | Custom spacing (e.g., 2px, 0.1em) |
| percentage | Relative to font size (e.g., 10%) |
π§ͺ Example Usage
1. Basic Custom Offset
Basic Offset
.example {
text-decoration-line: underline;
text-underline-offset: 3px;
}2. Large Offset for Stylish Design
Large Offset
.stylish {
text-decoration-line: underline;
text-underline-offset: 8px;
}3. Using Percentage
Percentage Value
.percentage {
text-decoration-line: underline;
text-underline-offset: 15%;
}4. Combine with Thickness & Color
Full Styling Example
.fancy {
text-decoration-line: underline;
text-decoration-thickness: 3px;
text-decoration-color: #ff4d4d;
text-underline-offset: 6px;
}This creates a bold, modern underline with extra breathing space β great for headings or call-to-action links. π₯
β οΈ Important Notes
Note
text-decoration-line: underline is required for this property to work.Note
π Real-World Use Cases
- Modern underline effects on blog links βοΈ
- Cleaner, spaced underlines for titles π°
- Accessibility-friendly underline spacing π
- Premium UI styling for portfolios π¨
Modern Blog Link Example
a {
color: #222;
text-decoration-line: underline;
text-decoration-color: #0077ff;
text-decoration-thickness: 2px;
text-underline-offset: 4px;
}π Conclusion
The text-underline-offset property gives you fine control over underline positioning, helping you create clean, modern, and visually appealing text styles. Use it along with text-decoration-thickness,text-decoration-style, and text-decoration-color for maximum creativity. π