A headline cut into bands like a sliced print: hover and the bands slide apart in alternate directions, revealing the word in a second colour through the cut.
Lettering made of glass: see-through letters with a bright top edge, a fine rim and a soft glow, and a highlight that glides across with the pointer.
Customize
Usage
import { GlassText } from "@/components/motionkit/glass-text";
<GlassText as="h1" className="text-8xl font-bold tracking-tight">
Clarity
</GlassText>Motion
The exact curves this component runs, plotted with Motion's own maths.
Highlight sweeps
Runs on its own
Highlight follows
Pointer moves
Headlines over photos, gradients and animated backgrounds, product launches, and hero words that should feel premium and light.
The letters keep a transparent fill and are painted with background-clip: text: a thin tint of colour for the body of the glass, a vertical gradient that pools light at the top and bottom edges as thick glass does, and a radial highlight whose position is a registered CSS custom property. Moving the pointer sets that property, and a keyframe sweeps it across now and then. A one-pixel light stroke gives the rim, and stacked drop shadows add a bright lip, depth and a soft tinted glow. It's still your real text.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/glass-text.jsonnpm install motionSave as components/motionkit/glass-text.tsx.
"use client";
import { useRef, type CSSProperties, type ElementType, type PointerEvent, type ReactNode } from "react";
type GlassTextProps = {
children: ReactNode;
/** The element to render, e.g. "h1". */
as?: ElementType;
/** A hint of colour in the glass and the glow it casts. */
tint?: string;
/** How clear the glass is, 0 (milky) to 1 (almost clear). */
clarity?: number;
/** A highlight that follows the pointer across the letters, and sweeps by itself now and then. */
sheen?: boolean;
className?: string;
};
/**
* Lettering made of glass: see-through letters with a bright top edge, a fine rim and a soft glow, so whatever is
* behind shows through. A highlight glides across them with the pointer. Best over colour or an image.
*/
export function GlassText({ children, as: Tag = "span", tint = "#B9C7FF", clarity = 0.6, sheen = true, className = "" }: GlassTextProps) {
const ref = useRef<HTMLElement>(null);
// how much of the glass body is tinted: clear glass lets nearly all of the colour behind through
const body = Math.round((1 - Math.min(1, Math.max(0, clarity))) * 22 + 4);
function move(event: PointerEvent) {
if (!sheen || event.pointerType === "touch") return;
const rect = ref.current!.getBoundingClientRect();
ref.current!.style.setProperty("--glass-x", `${((event.clientX - rect.left) / rect.width) * 100}%`);
ref.current!.dataset.lit = "";
}
const style = {
"--glass-x": "-30%",
backgroundImage: [
// the highlight that follows the pointer
sheen ? "radial-gradient(30% 120% at var(--glass-x) 30%, rgb(255 255 255 / 0.7), transparent 70%)" : "linear-gradient(transparent, transparent)",
// light pooling at the top edge and again near the bottom, as in a thick pane
`linear-gradient(180deg, rgb(255 255 255 / 0.85) 0%, rgb(255 255 255 / 0.28) 16%, rgb(255 255 255 / 0) 40%, rgb(255 255 255 / 0) 70%, rgb(255 255 255 / 0.4) 100%)`,
// the body of the glass, lightly tinted
`linear-gradient(color-mix(in srgb, color-mix(in srgb, ${tint} 45%, white) ${body}%, transparent), color-mix(in srgb, color-mix(in srgb, ${tint} 45%, white) ${body}%, transparent))`,
].join(", "),
backgroundRepeat: "no-repeat",
WebkitBackgroundClip: "text",
backgroundClip: "text",
color: "transparent",
WebkitTextStroke: "1.25px rgb(255 255 255 / 0.55)",
// seen through the clear letters, an offset tinted shadow reads as light bending through thick glass
textShadow: `0 1px 0 rgb(255 255 255 / 0.2), 3px 6px 12px color-mix(in srgb, ${tint} 40%, transparent), -2px -2px 6px rgb(255 255 255 / 0.08)`,
filter: `drop-shadow(0 12px 24px rgb(0 0 0 / 0.3)) drop-shadow(0 0 18px color-mix(in srgb, ${tint} 22%, transparent))`,
transition: "--glass-x 0.6s",
} as CSSProperties;
return (
<>
<style>{`@property --glass-x{syntax:"<percentage>";inherits:true;initial-value:-30%}@keyframes glass-sweep{0%,60%{--glass-x:-30%}100%{--glass-x:130%}}[data-glass-text]:not([data-lit]){animation:glass-sweep 6s ease-in-out infinite}@media (prefers-reduced-motion:reduce){[data-glass-text]{animation:none!important}}`}</style>
<Tag
ref={ref}
data-glass-text={sheen ? "" : undefined}
onPointerMove={move}
onPointerLeave={() => {
delete ref.current?.dataset.lit;
}}
className={`inline-block ${className}`}
style={style}
>
{children}
</Tag>
</>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | The text. |
| tint | string | "#B9C7FF" | A hint of colour in the glass and its glow. |
| clarity | number | 0.6 | How clear the glass is, 0 (milky) to 1 (almost clear). |
| sheen | boolean | true | A highlight that follows the pointer and sweeps by now and then. |
| as | ElementType | "span" | Element to render, e.g. h1. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Nothing beyond React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/glass-text.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the highlight no longer sweeps by itself.
A headline cut into bands like a sliced print: hover and the bands slide apart in alternate directions, revealing the word in a second colour through the cut.
Crisp letters lit from behind by a soft, slowly flowing glow of colour, the way a new AI feature or a launch headline glows.
A headline that resolves like an image loading: it arrives as a few big blocks of colour, and each step halves the pixels until the letters snap sharp.
Clarity