Text Shimmer
A gradient that sweeps across text for loading labels or emphasis.
Preview
"use client";
import { TextShimmer } from "@/components/motion/text-shimmer";
export function TextShimmerPreview() {
return (
<div className="flex flex-col gap-4">
<TextShimmer className="text-3xl font-semibold">Loading projects…</TextShimmer>
<TextShimmer duration={1.5} className="text-sm">Faster shimmer</TextShimmer>
</div>
);
}
// beui.dev/components/motion/text-animation/shimmer
import { cn } from "@/lib/utils";
import type { ElementType, ReactNode } from "react";
import {
TEXT_SHIMMER_CLASS_NAME,
TEXT_SHIMMER_KEYFRAMES,
textShimmerStyle,
} from "@/lib/text-shimmer";
export interface TextShimmerProps {
children: ReactNode;
/** Element to render the text as. Default: "span" */
as?: ElementType;
/** Length of one shimmer sweep (s). Default: 2.5 */
duration?: number;
/** Classes merged onto the text element. */
className?: string;
}
export function TextShimmer({ children, as: Comp = "span", duration = 2.5, className }: TextShimmerProps) {
return (
<>
<style>
{TEXT_SHIMMER_KEYFRAMES}
</style>
<Comp
style={textShimmerStyle(duration)}
className={cn(
"inline-block",
TEXT_SHIMMER_CLASS_NAME,
className,
)}
>
{children}
</Comp>
</>
);
}
Add it with the shadcn CLI, or copy the source manually.
npx shadcn add https://beui.dev/r/theme.json. Theme setupInstall dependencies
npm i clsx tailwind-mergeAdd util files
import type { CSSProperties } from "react";
// The reduced-motion rule travels with the component. The site's globals.css calms CSS
// animation globally, but the registry bundles imports only, so an installed
// copy never receives that reset.
//
// `!important` because the sweep is an inline style, which outranks a plain rule
// in a media query. It selects a marker class carried by TEXT_SHIMMER_CLASS_NAME
// so it also reaches consumers that build their own span out of these exports.
export const TEXT_SHIMMER_KEYFRAMES =
"@keyframes beui-text-shimmer{from{background-position:200% 0}to{background-position:-200% 0}}" +
"@media (prefers-reduced-motion: reduce){.beui-text-shimmer{animation:none !important}}";
export const TEXT_SHIMMER_CLASS_NAME =
"beui-text-shimmer bg-[length:200%_100%] bg-clip-text text-transparent bg-[linear-gradient(110deg,var(--muted-foreground)_30%,var(--foreground)_50%,var(--muted-foreground)_70%)]";
/**
* Only the moving highlight band, transparent elsewhere. Laid over text drawn
* in pieces (a letter cascade), so one band sweeps the whole phrase instead
* of every piece carrying, and flashing, its own gradient.
*/
export const TEXT_SHIMMER_HIGHLIGHT_CLASS_NAME =
"beui-text-shimmer bg-[length:200%_100%] bg-clip-text text-transparent bg-[linear-gradient(110deg,transparent_30%,var(--foreground)_50%,transparent_70%)]";
export function textShimmerStyle(duration: number): CSSProperties {
return {
animation: `beui-text-shimmer ${duration}s linear infinite`,
};
}
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Copy the source code
// beui.dev/components/motion/text-animation/shimmer
import { cn } from "@/lib/utils";
import type { ElementType, ReactNode } from "react";
import {
TEXT_SHIMMER_CLASS_NAME,
TEXT_SHIMMER_KEYFRAMES,
textShimmerStyle,
} from "@/lib/text-shimmer";
export interface TextShimmerProps {
children: ReactNode;
/** Element to render the text as. Default: "span" */
as?: ElementType;
/** Length of one shimmer sweep (s). Default: 2.5 */
duration?: number;
/** Classes merged onto the text element. */
className?: string;
}
export function TextShimmer({ children, as: Comp = "span", duration = 2.5, className }: TextShimmerProps) {
return (
<>
<style>
{TEXT_SHIMMER_KEYFRAMES}
</style>
<Comp
style={textShimmerStyle(duration)}
className={cn(
"inline-block",
TEXT_SHIMMER_CLASS_NAME,
className,
)}
>
{children}
</Comp>
</>
);
}
as?ElementTypeElement to render the text as. Default: "span"
spanduration?numberLength of one shimmer sweep (s). Default: 2.5
2.5className?stringClasses merged onto the text element.
—Text Scramble
Changed characters cycle through random glyphs before they settle.
Dia Text Animation
A fixed sentence whose last word cycles in behind a colorful sweep.
Text Reveal
Words or letters slide up into place with a spring and soft blur.
Text Cascade
Old letters drop away as new ones roll in, one at a time from the left.
Number Animation
Animated number primitives for count-up values, rolling tickers, and fixed-slot digit swaps.
Action Swap
CTA button and slot primitives for swapping text and icons with blur motion.
Loader
Loading indicator with seventeen variants: spinner, dots, bars, dot-matrix, dither, morph, comet, scramble, metaballs, newton, helix, percent, and five terminal-style ascii spinners. Scales from one size prop, uses currentColor, and reduced-motion swaps every transform for a calm opacity pulse.
Updated