GitHub

Glass

Clear liquid glass with SVG refraction and a CSS fallback, and a CSS-only frosted material.

Preview

Compare an ordinary and a glass surface in one scene, and switch between Clear glass and frosted glass. The status line reports whether the browser renders SVG refraction or the CSS fallback. Switch the site appearance to compare light and dark themes.

Loading example…

Installation

pnpm dlx shadcn@latest add @sui/glass

Usage

import { GlassSurface } from "@workspace/ui/components/glass";

<GlassSurface className="rounded-2xl bg-background p-6">
  Glass surface
</GlassSurface>

Every glass-capable component takes two props, and describes only itself:

PropResult
omittedAn ordinary component.
glassClear liquid glass with the defaults.
glass={{ edge, strength, tint, tintOpacity, textGlow }}Clear liquid glass with these settings.
frostedFrosted glass, drawn by CSS alone.

Nothing is inherited: a component is glass only when it says so, whatever surrounds it, and settings never pass from a parent to its children. When both are set, glass wins. glass={false} is the same as omitting it, so glass={enabled} works.

import { Button } from "@workspace/ui/components/button";
import { GlassSurface } from "@workspace/ui/components/glass";

<GlassSurface glass={{ edge: "vertical" }} />
<GlassSurface frosted />
<Button glass>Action</Button>

Pass render to keep native semantics, for example <GlassSurface render={<nav />} />. GlassSurface is Clear unless frosted is set. Each glass component is an independent request; observers, listeners and the SVG renderer are shared internally, so no Provider is required.

Rendering

Clear glass renders native SVG refraction: a geometric displacement map bends the live backdrop along the edges with feDisplacementMap, then blurs and saturates it. Nothing is captured, so video, scrolling and animation stay live at the display's frame rate.

The CSS material is its fallback. It applies before a surface is measured, in browsers that cannot paint SVG backdrops (Safari), under prefers-reduced-transparency, prefers-reduced-motion or forced colors, and if the renderer fails. Fully opaque paint covers the backdrop, so such surfaces keep CSS with the shared edge highlight. Reduced transparency, reduced motion and forced colors show an opaque base with native focus styles.

Frosted glass never runs JavaScript or loads the renderer: it is a stylesheet rule on the component's own element.

Loading example…

refreshGlass(target?) re-measures Clear surfaces inside an element or ref, or all of them when the target is omitted. Call it after changing paint the runtime cannot observe.

Materials

The two materials follow Apple's Clear and Regular variants; the values are Web approximations, not Apple specifications.

PropTintBlurRefraction and edge lightUse
glass12%4px SVG, 6px CSS fallbackYesSee-through glass over media; the backdrop stays recognizable.
frosted65%24px CSSNoFrosted glass that keeps text legible over busy content.

Clear refracts with strength 22; both saturate by 1.3. The tint comes from the component's own background, so primary and destructive paint keep their color. glass={{ tintOpacity }} overrides Clear's tint. Frosted glass reads its tint from the component's surface color; set --frosted-base, --frosted-opacity or --frosted-blur in CSS to restyle it. From bottom to top, a surface composes the blurred or refracted backdrop, the tint, component paint, Clear's edge highlight and content.

Loading example…

Edge light

glass={{ edge }} chooses how light falls on a Clear rim:

  • "diagonal" (default): a thin rim lit from the top-left and bottom-right corners, fading along the sides.
  • "vertical": a lit bevel with reflections along the top and bottom edges.
Loading example…

The highlight strength is built in and follows pixel density continuously (0.15 × device pixel ratio, from 0.15 to 0.3), so 1x screens draw a fainter edge. The rim itself is 0.9px wide on every screen.

Edge light belongs to Clear glass, which hides decorative borders and rings. Keyboard focus adds a separate visible outline; forced colors use the system Highlight color. Frosted glass has no edge light. As on iOS, its contrast and shadow outline it, so the component's own border and decorative ring step aside too; it keeps focus rings, and Increase Contrast (prefers-contrast: more) brings the border back.

Popups

Popups choose their material like any other component: put glass or frosted on the content, such as PopoverContent, SelectContent or DialogContent. Roots like Popover, Select or Dialog take no glass prop. Frosted glass suits menus and dialogs over busy content, as on Apple platforms. Floating layers share one soft, diffuse shadow.

<Select>
  <SelectTrigger glass />
  <SelectContent frosted>{/* items */}</SelectContent>
</Select>
Loading example…

Controls and content

Glass belongs to navigation, controls and floating layers; content stays ordinary.

  • Controls inside a glass surface stay ordinary. Prefer ghost or outline variants on glass, which sit on the material without a solid fill.
  • Glass never blurs twice: a glass or frosted component inside another glass layer keeps its tint and edge light but does not blur or refract the backdrop again, because a nested backdrop filter would only frost the outer layer's content. A popup is not inside its trigger's layer, so a glass menu opened from a glass bar is its own full layer.
  • A glass ButtonGroup is one capsule its buttons sit on; in a group of groups, give each inner group its own glass. Toolbar, TabsList, PaginationContent and Command work the same way.
  • Form fields (Input, Textarea, InputGroup, SelectTrigger, TagInput) with glass are capsules like iOS search fields, and brighten slightly while focused.
  • Switch and Slider with glass turn their thumb into a Clear lens only while dragged. Pressed buttons bloom slightly, and glass buttons also brighten.
  • Components that render their glass pieces themselves pass the prop on: TabBar (its bar and lens), NavigationMenu (its popup), Toaster (its toasts), Image (its preview controls), ColorPicker (its trigger and popup), PaginationControls and PaginationPageSize.
  • Card, QR code, Accordion, Calendar, editors and viewers are content. Card and QRCode accept glass or frosted, for example for a widget over media.
Loading example…
import { Card } from "@workspace/ui/components/card";
import { GlassSurface } from "@workspace/ui/components/glass";

<GlassSurface>{/* ordinary content and ghost controls */}</GlassSurface>
<Card glass>{/* a glass widget */}</Card>
Loading example…

Clear glass keeps its resting edge light and adds a separate outline for keyboard focus, while frosted glass keeps the component's focus ring; ordinary components keep their theme and focus styling. Glass shows the backdrop through, so secondary text moves toward the foreground. Over bright, busy backdrops, glass={{ textGlow: true }} adds a tight glow in the material's own tint that hugs text and icons; it is off by default. The glow only shows where the backdrop fights the text, so it stays legible in light and dark mode. Frosted glass's denser tint keeps text legible without a glow. Reduced transparency turns the glow and secondary text change off along with the glass.

API reference

PropTypeDefault / behavior
Component glassboolean | GlassConfigClear liquid glass on this component; GlassSurface defaults to true.
Component frostedbooleanFrosted glass on this component; glass wins when both are set.
Config edge"diagonal" | "vertical""diagonal".
Config strengthnumber22.
Config tintstringComponent background.
Config tintOpacitynumber0.12.
Config textGlowbooleanfalse.
refreshGlass(target?)(target?: GlassTarget) => voidRe-measure surfaces inside the target, or all when omitted.
GlassSurfaceuseRender propsNative div props, plus render to change the element.