The text waits as a faint ghost until a soft spotlight sweeps across it, then the light widens to show the whole line. Two mask layers: a radial spot and a low-alpha fill for the ghost.
Also known as: spotlight text effect css, flashlight text reveal, radial mask text reveal.
<div class="txt-spotlight-text-reveal">Center stage</div>
.txt-spotlight-text-reveal {
--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-block;
padding: 0 0.3em;
white-space: nowrap;
color: var(--c);
-webkit-mask-image: radial-gradient(circle, #000 30%, transparent 62%), linear-gradient(rgb(0 0 0 / 0.14) 0 0);
mask-image: radial-gradient(circle, #000 30%, transparent 62%), linear-gradient(rgb(0 0 0 / 0.14) 0 0);
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-size: 3em 3em, 100% 100%;
mask-size: 3em 3em, 100% 100%;
-webkit-mask-position: -1.5em 50%, 0 0;
mask-position: -1.5em 50%, 0 0;
animation: txt-spotlight-text-reveal-sweep 2s forwards, txt-spotlight-text-reveal-lit 0s 2s forwards;}
/* sweep left to right, then open up to the whole line */
@keyframes txt-spotlight-text-reveal-sweep {
0% {
-webkit-mask-position: -1.5em 50%, 0 0; mask-position: -1.5em 50%, 0 0;
-webkit-mask-size: 3em 3em, 100% 100%; mask-size: 3em 3em, 100% 100%;
animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
}
55% {
-webkit-mask-position: calc(100% + 1.5em) 50%, 0 0; mask-position: calc(100% + 1.5em) 50%, 0 0;
-webkit-mask-size: 3em 3em, 100% 100%; mask-size: 3em 3em, 100% 100%;
animation-timing-function: cubic-bezier(0.6, 0, 0.3, 1);
}
100% {
-webkit-mask-position: 50% 50%, 0 0; mask-position: 50% 50%, 0 0;
-webkit-mask-size: 400% 400%, 100% 100%; mask-size: 400% 400%, 100% 100%;
}
}
/* drop the mask once the light is fully up */
@keyframes txt-spotlight-text-reveal-lit {
to { -webkit-mask-image: none; mask-image: none; }
}
@media (prefers-reduced-motion: reduce) {
.txt-spotlight-text-reveal, .txt-spotlight-text-reveal *, .txt-spotlight-text-reveal::before, .txt-spotlight-text-reveal::after, .txt-spotlight-text-reveal *::before, .txt-spotlight-text-reveal *::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.