Default underlines hug the text and slice through the tails of letters like g and y. A little distance makes links much easier to read, and CSS has a property for it.
a {
text-decoration: underline;
text-underline-offset: 0.2em;
}
The property sets how far the underline sits from its default position. The initial value is auto, where the browser decides. A length overrides both the browser default and any offset suggested by the font file. MDN recommends em, so the offset grows and shrinks with the font size.
Combine it with text-decoration-thickness and text-decoration-color to style links without borders or background tricks:
a {
text-decoration-color: currentColor;
text-decoration-thickness: 1px;
text-underline-offset: 0.25em;
}
A percentage is a percentage of 1em in the element’s own font. It is inherited as a relative value and stays constant across the whole box, even when child elements have different font sizes.
MDN marks the property as widely available, with support across browsers since November 2020.
The caveat is the scope. It affects only underlines, not overlines or strikethroughs, and it is not part of the text-decoration shorthand, so setting that shorthand later does not reset your offset. If you need the offset on specific links only, set it on those selectors.
Further reading: MDN: text-underline-offset