A translucent highlighter stroke draws in behind the words after a short delay, as if someone marked the important line. Plays once, then stays.
Also known as: marker highlight text, text underline highlight.
<div class="txt-highlight-sweep">The part that matters</div>
.txt-highlight-sweep {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
display: inline;
background: linear-gradient(color-mix(in srgb, var(--c) 45%, transparent), color-mix(in srgb, var(--c) 45%, transparent)) no-repeat 0 85%;
background-size: 0% 40%;
animation: txt-highlight-sweep-draw 0.8s ease-out 0.4s forwards;}
@keyframes txt-highlight-sweep-draw {
to { background-size: 100% 40%; }
}
@media (prefers-reduced-motion: reduce) {
.txt-highlight-sweep, .txt-highlight-sweep *, .txt-highlight-sweep::before, .txt-highlight-sweep::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.