Shimmer Text
Text with a band of light that sweeps across it on a loop, for in-progress status lines.
Preview
Summarising the launch thread
Step 3 of 4
- Read 14 comments from Ines and Malik
- Grouped feedback into 3 themes
- Drafting a reply to Priya…
- Check tone and length
Building your weekly report
Syncing 1,204 of 3,180 filesInstall
Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.
npx shadcn@latest add https://pebbleui.com/r/shimmer-text.jsonProps
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "span" | "p" | "div" | "span" | Element rendered. |
| duration | number | 2 | Seconds per sweep. |
| spread | number | 20 | Width of the band, as a percentage of the gradient. Clamped to 0–33 so the loop has no jump. |
| children | ReactNode | — | Inline text or inline elements that inherit color. |
Build notes
A text gradient moved behind the glyphs. The element gets `background-clip: text` and transparent text, and a `--shimmer-gradient` of five stops (muted, a color-mix shoulder, the tone's band colour, a shoulder, muted) with the bright band `spread`% wide. The background is 300% of the element's width, so the band starts and ends fully off the text and the loop restart is invisible. Motion animates `background-position` from `100% 0` to `0% 0`, eased in-out and repeating with a `pause` rest between sweeps. Reduced motion is handled in CSS (`motion-reduce:bg-none` plus the muted text color) rather than in JS, so server and client markup match and the text is readable before hydration. **Pebble (2026-11-03).** Added `tone` and `pause`. `tone="ember"` paints the band with `--accent` for a live process (an agent running, a sync in flight) and is meant to be used sparingly; `ink` stays the default; the root carries `data-tone`. The gradient gained a soft shoulder on each side of the band (a 55% `color-mix` of band and muted at a quarter-spread from centre) so the band edges no longer read as a stripe. The sweep is now eased (`easeInOut`) with a `repeatDelay` of `pause` seconds, so it reads as light passing over the text rather than a conveyor belt. Reduced-motion handling is unchanged. <!-- PEBBLE-LICENSE -->
View source
registry/text/shimmer-text/shimmer-text.tsx
"use client";
/* PEBBLE-LICENSE
Built by Pebble. Component: shimmer-text.
First-party license: MIT
The following first-party terms apply only to original Pebble material.
MIT License
Copyright (c) 2026 Praxys Solutions LLC (Pebble)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */
import * as React from "react";
import { motion } from "motion/react";
import { cn } from "@/lib/utils";
// Hydration-safe reduced motion: the server (and the hydration pass) render
// "no preference", then the real preference applies right after hydration.
const subscribeReduce = (onChange: () => void) => {
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
mq.addEventListener("change", onChange);
return () => mq.removeEventListener("change", onChange);
};
const getReduce = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const useReduceMotion = () => React.useSyncExternalStore(subscribeReduce, getReduce, () => false);
const elements = {
span: motion.span,
p: motion.p,
div: motion.div,
} as const;
// The band colour per tone. Ink is the default; ember marks a live process
// (an agent running, a sync in flight) and should be used sparingly.
const bands = {
ink: "var(--foreground)",
ember: "var(--accent)",
} as const;
export type ShimmerTextProps = Omit<
React.ComponentProps<"span">,
"children" | "style" | "onAnimationStart" | "onDrag" | "onDragStart" | "onDragEnd"
> & {
as?: keyof typeof elements;
/** Seconds per sweep. */
duration?: number;
/** Width of the band, as a percentage of the gradient (0–33). */
spread?: number;
/** Seconds of rest between sweeps. */
pause?: number;
/** Colour of the band of light: ink (default) or the ember accent. */
tone?: keyof typeof bands;
children: React.ReactNode;
style?: React.CSSProperties;
};
export function ShimmerText({
as = "span",
duration = 2,
spread = 20,
pause = 0.4,
tone = "ink",
className,
style,
children,
...props
}: ShimmerTextProps) {
const reduceMotion = useReduceMotion();
// The three elements take the same props here; narrow to one for typing.
const Comp = elements[as] as typeof motion.span;
// Past 33% the band would already overlap the text on the first frame and
// jump at each loop restart.
const half = Math.min(Math.max(Number.isFinite(spread) ? spread : 20, 0), 33) / 2;
const rest = Number.isFinite(pause) && pause > 0 ? pause : 0;
const resolvedTone = Object.hasOwn(bands, tone) ? tone : "ink";
const band = bands[resolvedTone];
return (
<Comp
data-slot="shimmer-text"
data-tone={resolvedTone}
// Reduced motion is handled in CSS so server and client markup match:
// the gradient is dropped and the text falls back to the muted colour.
className={cn(
as === "span" ? "inline-block" : "w-fit",
"bg-[image:var(--shimmer-gradient)] bg-size-[300%_100%] bg-clip-text bg-no-repeat text-transparent",
"motion-reduce:bg-none motion-reduce:text-muted-foreground",
className,
)}
style={
{
// Three times the text width, so the band starts and ends fully off
// the glyphs and the loop has no visible jump. A soft shoulder on
// each side of the band keeps its edges from reading as a stripe.
"--shimmer-gradient": `linear-gradient(90deg, var(--muted-foreground) ${50 - half}%, color-mix(in oklab, ${band} 55%, var(--muted-foreground)) ${50 - half / 2}%, ${band} 50%, color-mix(in oklab, ${band} 55%, var(--muted-foreground)) ${50 + half / 2}%, var(--muted-foreground) ${50 + half}%)`,
backgroundPosition: "100% 0",
...style,
} as React.CSSProperties
}
animate={reduceMotion ? undefined : { backgroundPosition: ["100% 0", "0% 0"] }}
// Eased rather than linear, with a short rest between sweeps, so it
// reads as light passing over the text rather than a conveyor belt.
transition={{ duration, ease: "easeInOut", repeat: Infinity, repeatDelay: rest }}
{...props}
>
{children}
</Comp>
);
}
