Custom text decorations
Style, trim and animate underlines, overlines and strikethroughs on any text, with real text-decoration properties, not borders or background gradients. Each section shows the result and the CSS that produces it. Every value is a custom property, so the styles are easy to change.
Several of these properties are new. Most are wrapped in @supports and fall back to a plain
underline or border, and the rest are simply ignored where unsupported. The list shows what this browser supports.
text-decoration
Line, style, color and thickness in one shorthand, with text-underline-offset for the gap.
Underline, overline and strikethrough
:where(.deco) {
text-decoration: underline solid var(--deco-color) var(--deco-thickness);
text-underline-offset: 0.2em;
}
.deco-over { text-decoration-line: overline; }
.deco-through { text-decoration-line: line-through; }
text-decoration-skip-ink
auto breaks the line around descenders. none draws straight through. all
skips ink everywhere, including ideographic text such as Japanese, where auto does not.
Gypsy jumping
今日は天気
auto
Gypsy jumping
今日は天気
none
Gypsy jumping
今日は天気
all
.skip-ink {
text-decoration-skip-ink: all; /* auto | none | all */
}
text-decoration-skip-spaces
Controls whether the line is drawn under leading and trailing spaces, or all spaces. Each sample has two spaces at both ends and one between words.
two words
none – spaces are decorated
two words
start end – default, ends skipped
two words
all – every space skipped
.skip-spaces {
white-space: pre; /* keep the spaces so there is something to skip */
text-decoration-skip-spaces: all; /* none | all | start | end | start end */
}
text-decoration-inset
Positive values pull the ends of the line inward, negative values push them outward. Transitioning it gives a hover reveal with no border or background gradient.
Trimmed
text-decoration-inset: var(--deco-inset)
Extended
text-decoration-inset: calc(var(--deco-inset) * -1)
Hover or focus: an animated underline
.inset-trim { text-decoration-inset: var(--deco-inset); }
.inset-extend { text-decoration-inset: calc(var(--deco-inset) * -1); }
/* Hover reveal: start with the end trimmed by 100%, then return it to 0 */
.reveal {
text-decoration-inset: 0 100%;
transition: text-decoration-inset var(--reveal-duration) var(--reveal-easing);
}
.reveal:is(:hover, :focus-visible) {
text-decoration-inset: 0 0;
}
Pseudo-element line
A border-shape squiggle on a pseudo-element replaces the underline, and clip-path
draws it on. Without border-shape the line is straight but still draws on.
.draw::after {
border-shape: shape(from 0% 50%, curve to 20% 50% with 5% 0% / 15% 100%, /* … */);
clip-path: inset(-1em 100% -1em 0); /* fully hidden */
transition: clip-path var(--draw-duration) ease-out;
}
.draw:is(:hover, :focus-visible)::after {
clip-path: inset(-1em 0 -1em 0); /* fully drawn */
}
background-clip: border-area
The background is painted only under the border, giving a gradient outline while the inside stays transparent.
.chip {
border: var(--ring-width) solid transparent;
background: linear-gradient(135deg, var(--ring-start), var(--ring-end)) border-box;
background-clip: border-area;
}
border-shape
The border follows a shape border-radius cannot draw, so a word can be tagged without extra markup
or SVG.
Read the new notes.
.tag {
border: var(--shape-stroke) solid var(--shape-color);
border-shape: polygon(0 0, 85% 0, 100% 50%, 85% 100%, 0 100%);
}