Shimmer
Drafting the Numscript…
Installation#
npx @formance/ds init already gives you shimmer. The utility ships with the shadcn package, and the Formance globals.css imports it.
Otherwise, install the shadcn package:
npm install -D shadcnThen import the shared utilities in your global CSS file, after tw-animate-css:
@import 'tailwindcss';@import 'tw-animate-css';@import 'shadcn/tailwind.css';Usage#
| Class | Styles |
|---|---|
shimmer | background-clip: text; animation: tw-shimmer var(--shimmer-duration, 2s) linear infinite; |
shimmer-once | animation-iteration-count: 1; |
shimmer-reverse | animation-direction: reverse; |
shimmer-none | --shimmer-image: none; --shimmer-text-fill: currentColor; |
shimmer-color-<color> | --shimmer-color: <color>; |
shimmer-color-[<value>] | --shimmer-color: <value>; |
shimmer-color-<color>/<pct> | --shimmer-color: color-mix(in oklch, <color> <pct>, transparent); |
shimmer-duration-<number> | --shimmer-duration: calc(<number> * 1ms); |
shimmer-spread-<number> | --shimmer-spread: calc(var(--spacing) * <number>); |
shimmer-spread-[<value>] | --shimmer-spread: <value>; |
shimmer-angle-<number> | --shimmer-angle: calc(<number> * 1deg); |
Add shimmer to a text element.
<p className="shimmer text-muted-foreground">Drafting the Numscript…</p>The shimmer is built on currentColor, so it adapts to the element:
- The highlight is derived from the text color, with no configuration needed.
- It works on any color, from
text-muted-foregroundto brand colors. - In dark mode, the highlight automatically brightens to stay visible.
The effect is pure CSS. The text is painted with background-clip: text, and the highlight sweeps across it in a seamless loop.
With Marker#
The shimmer composes with any component that renders text. A common pattern is a Marker showing a live status while the assistant is working:
<Marker role="status"> <MarkerContent className="shimmer">Thinking…</MarkerContent></Marker>Color#
Use shimmer-color-<color> to set the highlight color explicitly. It accepts theme colors with an optional opacity modifier, or any arbitrary color value.
Reading the ledger…
Reading the ledger…
<p className="shimmer shimmer-color-primary/60">Reading the ledger…</p><p className="shimmer shimmer-color-[#378ADD]">Reading the ledger…</p>Duration#
Use shimmer-duration-<number> to set the duration of one sweep in milliseconds. The default is 2000, i.e. 2s.
Drafting the Numscript…
shimmer
Drafting the Numscript…
shimmer-duration-1000
<p className="shimmer shimmer-duration-1000">Drafting the Numscript…</p>Spread#
Use shimmer-spread-<number> to set the width of the highlight band using the spacing scale. The default is calc(3ch + 40px): a fixed base plus a 3ch term that scales with the font size.
Drafting the Numscript…
shimmer-spread-4
Drafting the Numscript…
shimmer-spread-24
<p className="shimmer shimmer-spread-24">Drafting the Numscript…</p>For one-off values, use an arbitrary length or percentage:
<p className="shimmer shimmer-spread-[5rem]">Drafting the Numscript…</p>Angle#
Use shimmer-angle-<number> to set the tilt of the highlight band in degrees. The default is 20.
Drafting the Numscript…
shimmer
Drafting the Numscript…
shimmer-angle-45
<p className="shimmer shimmer-angle-45">Drafting the Numscript…</p>Reverse#
Use shimmer-reverse to sweep the highlight in the opposite direction. In RTL layouts the sweep already follows the reading direction. See RTL.
<p className="shimmer shimmer-reverse">Drafting the Numscript…</p>Play Once#
Use shimmer-once to play a single sweep instead of looping, useful as a reveal when streaming completes. Pair it with shimmer-duration-<number> to control how long the sweep takes.
<p className="shimmer shimmer-duration-1100 shimmer-once"> Schema v2 inserted.</p>Disabling the Shimmer#
Use shimmer-none to turn the effect off and render the text normally. It works in any class order, so the typical use is responsive or stateful:
Drafting the Numscript…
shimmer md:shimmer-none
<p className="shimmer md:shimmer-none">Drafting the Numscript…</p>Fallback#
The shimmer is built on modern color features, relative color syntax and color-mix(), which are available in all current browsers. In older browsers without support, the highlight gradient is dropped and the text can render transparent. If you target older browsers, apply shimmer conditionally with a supports-* variant:
<p className="supports-[color:oklch(from_white_l_c_h)]:shimmer"> Drafting the Numscript…</p>Reduced Motion#
When the user prefers reduced motion, the animation is disabled automatically and the text renders normally. There is nothing to configure.
RTL#
The sweep follows the reading direction, left to right in LTR and right to left in RTL, with no extra classes. Use shimmer-reverse to flip the direction manually.
Reading the ledger…
dir="ltr"
جارٍ قراءة السجل…
dir="rtl"