Skip to content
Thrum

Text shimmer

Text with a band of light that travels across it, for a label that says work is under way: generating, searching, thinking. It reads as busy without a spinner beside it. For a wait whose progress is known, use the progress bar; for a block of content still loading, the skeleton.

Install

npx shadcn@latest add https://thrumui.dev/r/text-shimmer.json

Adds components/ui/text-shimmer.tsx. Nothing else in your project changes.

import { TextShimmer } from "@/components/ui/text-shimmer";

Props

PropTypeDefaultDescription
childrenReactNodeRequiredThe text. It is drawn twice: once in its own colour, once as the band, which is hidden from screen readers.
durationnumberDefault 2Seconds for one pass of the band across the text. The next pass starts at once.
spreadnumberDefault 0.5The width of the band as a share of the text's width, from 0.1 to 1.
pausedbooleanDefault falsePause the sweep and hold a soft resting shimmer sheen across the centre of the text. Under reduced motion the sheen is hidden.
classNamestring–Extra classes, merged last. The text is the muted colour; the band is the foreground colour, so keep the text a step quieter than the foreground.
...propsComponentProps<"span">–Every other span attribute is passed through.

Motion and sound

Motion

  • A band of the foreground colour crosses the text from left to right, once every 2 seconds by default, at constant speed. It starts and ends off the text.
  • It is a CSS animation of the band's background position. The text never moves and the box never changes size.
  • paused stops the sweep and holds a single resting shimmer sheen across the centre of the text.
  • Reduced motion: no band. The text is still, in its own colour.

Sound

Silent. This component makes no sound.

Accessibility

  • The words are read once: the band is a copy of the text marked aria-hidden and inert.
  • The text keeps the muted colour, 4.5 to 1 against the page in both themes, at every frame. The band only draws the foreground colour over it, which is stronger still.
  • The shimmer adds no role. A label that appears while work runs belongs in a region with role="status", which announces it once.
  • It works at any size and wraps like plain text.

Source

components/ui/text-shimmer.tsx
"use client";

import type { ComponentProps, CSSProperties } from "react";

import { cn } from "@/lib/utils";

export type TextShimmerProps = ComponentProps<"span"> & {
  /** Seconds for one pass of the light band across the text. */
  duration?: number;
  /** The width of the band, as a share of the text's width, from 0.1 to 1. */
  spread?: number;
  /** Pause the sweep and hold a soft resting shimmer sheen across the centre of the text. */
  paused?: boolean;
};

/**
 * Text with a band of light that travels across it, for loading and "thinking" labels: "Generating summary", "Searching".
 * The text keeps its own colour at every moment; the band is a copy of the text in the foreground colour, hidden from
 * screen readers, so the words are read once and their contrast never drops. Under reduced motion the text is still.
 */
export function TextShimmer({ duration = 2, spread = 0.5, paused = false, className, style, children, ...props }: TextShimmerProps) {
  const band = Math.min(1, Math.max(0.1, spread));
  return (
    <span
      data-slot="text-shimmer"
      className={cn("relative inline-block text-muted-foreground", className)}
      // The gradient is three times as wide as the text, so its centre (the band) starts and ends off the text.
      // Half the band, in percent of that gradient: a band as wide as the text is a sixth of it either side of the centre.
      style={{ "--text-shimmer-band": `${(band * 100) / 6}%`, ...style } as CSSProperties}
      {...props}
    >
      {children}
      {paused && (
        <span
          aria-hidden="true"
          inert
          data-slot="text-shimmer-rest"
          className="pointer-events-none absolute inset-0 bg-[linear-gradient(90deg,transparent_calc(50%-var(--text-shimmer-band)),var(--foreground)_50%,transparent_calc(50%+var(--text-shimmer-band)))] bg-[length:220%_100%] bg-[position:50%_0] bg-no-repeat bg-clip-text text-transparent select-none motion-reduce:hidden"
        >
          {children}
        </span>
      )}
      <span
        aria-hidden="true"
        inert
        data-slot="text-shimmer-band"
        className={cn(
          "pointer-events-none absolute inset-0 bg-[linear-gradient(90deg,transparent_calc(50%-var(--text-shimmer-band)),var(--foreground)_50%,transparent_calc(50%+var(--text-shimmer-band)))] bg-[length:300%_100%] bg-[position:100%_0] bg-no-repeat bg-clip-text text-transparent select-none",
          "animate-[text-shimmer-sweep_2s_linear_infinite] motion-reduce:hidden",
          paused && "opacity-0 [animation-play-state:paused]",
        )}
        style={{ animationDuration: `${Math.max(0.1, duration)}s` }}
      >
        {children}
      </span>
    </span>
  );
}

Files and dependencies

Adds
components/ui/text-shimmer.tsx
Packages
None
Brings along
Nothing

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor