# Glass Text

> 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.

Category: Text · Free · Updated 2026-11-11 · Live demo: https://www.motionkitui.com/components/glass-text

## When to use it

Headlines over photos, gradients and animated backgrounds, product launches, and hero words that should feel premium and light.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/glass-text.json
```

Or copy `components/motionkit/glass-text.tsx` below. Requires react and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| 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. |

## Accessibility

- **Keyboard: Not applicable.** Text, not a control.
- **Screen readers: Pass.** It's your real text, styled; read, selected and translated normally.
- **Reduced motion: Pass.** With reduced motion on, the highlight no longer sweeps by itself.
- **Colour contrast: Partial.** See-through letters take their contrast from what's behind. Over the demo's backdrop the rim and highlights measure 4.3:1 and the clear body about 2:1, so use it for large display words over a calm backdrop.

## Source

```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>
    </>
  );
}
```
