CSS Highlight Sweep
A marker highlight that sweeps in behind key words from left to right when the page loads.
Launch twice as fast with less code.
<p class="hl-sweep">Launch <mark>twice as fast</mark> with less code.</p>
.hl-sweep {
max-width: 12em;
margin: 0;
color: #1f2937;
font: 700 26px/1.4 system-ui, sans-serif;
}
.hl-sweep mark {
padding: 0 0.15em;
color: inherit;
background: linear-gradient(100deg, #fde047, #facc15) no-repeat 0 0 / 0% 100%;
-webkit-box-decoration-break: clone;
box-decoration-break: clone;
animation: hl-sweep-in 0.9s 0.3s cubic-bezier(0.6, 0, 0.3, 1) forwards;
}
@keyframes hl-sweep-in {
to { background-size: 100% 100%; }
}
@media (prefers-reduced-motion: reduce) {
.hl-sweep mark {
animation: none;
background-size: 100% 100%;
}
}
About this CSS Highlight Sweep
This CSS Highlight Sweep is 26 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses keyframe animations, linear gradients and reduced-motion support. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#1f2937#fde047#facc15
How to use this highlight sweep
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.hl-sweepclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.