text-decoration-inset is Like Padding for Text Decorations
These articles are AI-generated summaries. Please check the original sources for full details.
The text-decoration-inset
The text-decoration-inset CSS property addresses a persistent issue in web design – text decorations like underlines extending beyond the first and last characters of text, leading to misalignment. This property, currently supported in Firefox 146+, allows for clipping of the decoration from the ends.
Why This Matters
For years, developers have relied on workarounds like pseudo-elements (::after) to achieve correctly aligned underlines, a solution that can be complex and inflexible. Native text decoration features offer advantages like responsiveness to text-decoration-thickness and text-underline-position, but were previously hampered by this alignment issue which drove the need for less maintainable solutions. The cost of imperfection negatively impacts design polish and attention to detail.
Key Insights
- Firefox 146+ Support: The property is currently implemented in Firefox version 146 and later.
- Length-Based Values:
text-decoration-insetutilizes<length>values, ideally usingemunits for scalability with font size. - Animation Potential: Transitioning or animating
text-decoration-insetcreates native animated underlines, avoiding reliance on less efficient pseudo-element techniques.
Working Example
a {
transition: 300ms;
text-decoration-inset: 0.046em 0.009em;
}
a:hover {
text-decoration-inset: calc(0.046em * 10);
}
Practical Applications
- Typography Focused Sites: News outlets or blogs can precisely control underline placement to create a cleaner, more professional look.
- Pitfall: Using absolute pixel values for
text-decoration-insetcan break when font sizes change, leading to misaligned decorations, makingemthe preferred unit.
References:
Continue reading
Next article
Threat Actors Exploit Zero-Day in WatchGuard Firebox Devices
Related Content
CSS `text-grow` Property Prototyped in Chrome Canary 145
Chrome Canary 145 introduces a `text-grow` property to fit text to container width, addressing a long-standing CSS layout challenge.
Mastering 3D Vertical Rotation with CSS rotateX()
The CSS rotateX() function enables 3D vertical rotation, essential for building high-performance UI components like flip cards and 3D accordions.
Masonry Layout is Now grid-lanes | CSS-Tricks
After years of debate, a standardized CSS masonry layout will be implemented using the `display: grid-lanes` property.