Skip to content

Glass Media Controls

Liquid Glass media controls over video: transport, scrubber and volume capsules, with the HIG 35% dimming layer.

  • Liquid Glass
  • Music & media
  • React only · 0 deps
  • 2 files
Full screen

Browser support · Real refraction (SVG displacement inside backdrop-filter) in Chromium browsers. Safari and Firefox fall back to a frosted blur with the same rim and highlights.

Install. One command, or copy the file.

$npx shadcn@latest add https://freedesignmd.com/r/glass-media-controls.json
  • Byte-identical to the preview
  • No Tailwind or config needed
  • SSR-safe · keyboard accessible
  • Respects reduced motion & transparency
components/liquid-glass/glass-media-controls.tsx
1/**
2 * GlassMediaControls, clear Liquid Glass playback controls for video/music.
3 *
4 * Clear glass is the HIG variant for controls over rich media: highly
5 * translucent so the picture shows through, with a refracting rim. Over bright
6 * footage, turn on `dim` for the 35% dimming layer so white glyphs stay legible.
7 *
8 * Pieces (all clear glass, separate capsules, no glass on glass):
9 * - transport: back 10 s · play/pause (XL) · forward 10 s
10 * - scrubber capsule: elapsed · track · remaining (thumb turns to glass while dragged)
11 * - volume capsule: mute toggle + level track
12 *
13 * Props: playing + onPlayingChange, time + duration (s) + onSeek(s),
14 * volume (0–1) + onVolumeChange, muted + onMutedChange, dim, title.
15 * Keyboard: all real <button>s and <input type="range">s (Arrow/Home/End).
16 * Browser support: refraction in Chromium; frosted glass elsewhere.
17 * Reduced motion: no press bounce or knob swell.
18 */
19import { useEffect, useRef, useState } from "react";
20import type { CSSProperties, ReactNode } from "react";
21import { GlassScope, LiquidGlass, useGlassEnv, useSpring } from "./liquid-glass";
22
23export interface GlassMediaControlsProps {
24 playing: boolean;
25 onPlayingChange: (p: boolean) => void;
26 time: number;
27 duration: number;
28 onSeek: (t: number) => void;
29 volume: number;
30 onVolumeChange: (v: number) => void;
31 muted: boolean;
32 onMutedChange: (m: boolean) => void;
33 dim?: boolean;
34 /** Accessible name of the media, e.g. "Tidelines, episode 3". */
35 title: string;
36 className?: string;
37}
38
39const fmt = (s: number) => {
40 const t = Math.max(0, Math.round(s));
41 const m = Math.floor(t / 60);
42 return `${m}:${String(t % 60).padStart(2, "0")}`;
43};
44
45/** Thin range track with a knob that becomes glass while dragged. */
46function Track({ value, max, step, label, valueText, onChange }: { value: number; max: number; step: number; label: string; valueText: string; onChange: (v: number) => void }) {
47 const env = useGlassEnv();
48 const knob = useRef<HTMLElement | null>(null);
49 const [active, setActive] = useState(false);
50 const lift = useSpring(0, (v) => {
51 const k = knob.current;
52 if (!k) return;
53 k.style.setProperty("--fd-gmc-k", v.toFixed(3));
54 }, { stiffness: 520, damping: 28 });
55 useEffect(() => {
56 if (env.reducedMotion) lift.set(active ? 1 : 0);
57 else lift.to(active ? 1 : 0);
58 }, [active, env.reducedMotion, lift]);
59 const pct = max ? Math.min(1, Math.max(0, value / max)) : 0;
60 return (
61 <span className={`fd-gmc-track${active ? " is-active" : ""}`} style={{ "--p": pct } as CSSProperties}>
62 <span className="fd-gmc-rail" aria-hidden="true">
63 <span className="fd-gmc-fill" />
64 </span>
65 <LiquidGlass ref={knob} as="span" className="fd-gmc-knob" variant="clear" radius="capsule" refraction={1.3} shadow={false} aria-hidden="true">
66 <span className="fd-gmc-knob-solid" />
67 </LiquidGlass>
68 <input
69 type="range"
70 className="fd-gmc-input"
71 min={0}
72 max={max}
73 step={step}
74 value={value}
75 aria-label={label}
76 aria-valuetext={valueText}
77 onChange={(e) => onChange(Number(e.target.value))}
78 onPointerDown={() => setActive(true)}
79 onPointerUp={() => setActive(false)}
80 onPointerCancel={() => setActive(false)}
81 onBlur={() => setActive(false)}
82 />
83 </span>
84 );
85}
86
87const I = ({ children, size = 24 }: { children: ReactNode; size?: number }) => (
88 <svg viewBox="0 0 24 24" width={size} height={size} fill="currentColor" aria-hidden="true">
89 {children}
90 </svg>
91);
92
93export function GlassMediaControls({ playing, onPlayingChange, time, duration, onSeek, volume, onVolumeChange, muted, onMutedChange, dim = false, title, className }: GlassMediaControlsProps) {
94 const vol = muted ? 0 : volume;
95 return (
96 <GlassScope>
97 <div className={["fd-gmc", className ?? ""].filter(Boolean).join(" ")} role="group" aria-label={`Playback controls, ${title}`}>
98 <style>{css}</style>
99 <div className="fd-gmc-transport">
100 <LiquidGlass as="button" type="button" className="fd-gmc-btn" variant="clear" dim={dim} interactive aria-label="Back 10 seconds" onClick={() => onSeek(Math.max(0, time - 10))}>
101 <Skip back />
102 </LiquidGlass>
103 <LiquidGlass as="button" type="button" className="fd-gmc-btn fd-gmc-play" variant="clear" dim={dim} interactive aria-label={playing ? "Pause" : "Play"} aria-pressed={playing} onClick={() => onPlayingChange(!playing)}>
104 <span className={`fd-gmc-pp${playing ? " is-playing" : ""}`} aria-hidden="true">
105 <I size={34}>
106 <path className="fd-gmc-pp-a" d="M7 4.6v14.8c0 .9 1 1.4 1.7.9l11.2-7.4a1.1 1.1 0 0 0 0-1.8L8.7 3.7C8 3.2 7 3.7 7 4.6Z" />
107 </I>
108 <I size={34}>
109 <rect x="5.5" y="4" width="4.6" height="16" rx="1.4" />
110 <rect x="13.9" y="4" width="4.6" height="16" rx="1.4" />
111 </I>
112 </span>
113 </LiquidGlass>
114 <LiquidGlass as="button" type="button" className="fd-gmc-btn" variant="clear" dim={dim} interactive aria-label="Forward 10 seconds" onClick={() => onSeek(Math.min(duration, time + 10))}>
115 <Skip />
116 </LiquidGlass>
117 </div>
118
119 <div className="fd-gmc-bar">
120 <LiquidGlass className="fd-gmc-scrub" variant="clear" dim={dim}>
121 <span className="fd-gmc-time">{fmt(time)}</span>
122 <Track value={time} max={duration} step={1} label="Seek" valueText={`${fmt(time)} of ${fmt(duration)}`} onChange={onSeek} />
123 <span className="fd-gmc-time">−{fmt(duration - time)}</span>
124 </LiquidGlass>
125 <LiquidGlass className="fd-gmc-vol" variant="clear" dim={dim}>
126 <button type="button" className="fd-gmc-mute" aria-label={muted ? "Unmute" : "Mute"} aria-pressed={muted} onClick={() => onMutedChange(!muted)}>
127 <I size={20}>
128 <path d="M4 9.2h3.3L12 5v14l-4.7-4.2H4a1 1 0 0 1-1-1v-3.6a1 1 0 0 1 1-1Z" />
129 {vol === 0 ? (
130 <path d="m15.5 9.5 5 5m0-5-5 5" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" fill="none" />
131 ) : (
132 <>
133 <path d="M15 9.2a4 4 0 0 1 0 5.6" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" fill="none" />
134 {vol > 0.5 ? <path d="M17.6 6.6a7.6 7.6 0 0 1 0 10.8" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" fill="none" /> : null}
135 </>
136 )}
137 </I>
138 </button>
139 <Track
140 value={Math.round(vol * 100)}
141 max={100}
142 step={1}
143 label="Volume"
144 valueText={`${Math.round(vol * 100)}%`}
145 onChange={(v) => {
146 onVolumeChange(v / 100);
147 if (muted && v > 0) onMutedChange(false);
148 }}
149 />
150 </LiquidGlass>
151 </div>
152 </div>
153 </GlassScope>
154 );
155}
156
157function Skip({ back = false }: { back?: boolean }) {
158 return (
159 <svg viewBox="0 0 28 28" width="26" height="26" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={back ? undefined : { transform: "scaleX(-1)" }}>
160 <path d="M9.5 6.5A9.5 9.5 0 1 1 4.6 15" />
161 <path d="M9.8 2.6 9.5 6.5l3.9.6" />
162 <text x="14" y="18" textAnchor="middle" fill="currentColor" stroke="none" fontSize="8.5" fontWeight="700" fontFamily="ui-sans-serif,-apple-system,Inter,sans-serif" style={back ? undefined : { transform: "scaleX(-1)", transformOrigin: "14px 14px" }}>
163 10
164 </text>
165 </svg>
166 );
167}
168
169const css = `
170.fd-gmc,.fd-gmc *,.fd-gmc *::before,.fd-gmc *::after{box-sizing:border-box}
171.fd-gmc{display:flex;flex-direction:column;align-items:center;gap:18px;width:100%;margin:0;padding:0;color:#fff;font:600 13px/1 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:normal}
172.fd-gmc-transport{display:flex;align-items:center;gap:22px;margin:0;padding:0}
173.fd-gmc-btn{display:grid;place-items:center;width:58px;height:58px;margin:0;padding:0;color:#fff}
174.fd-gmc-btn svg{display:block}
175.fd-gmc-play{width:84px;height:84px}
176.fd-gmc-pp{position:relative;display:block;width:34px;height:34px;margin:0;padding:0}
177.fd-gmc-pp svg{position:absolute;inset:0;transition:opacity var(--fd-dur-2) var(--fd-ease-out),transform var(--fd-dur-3) var(--fd-spring)}
178.fd-gmc-pp svg:first-child{transform:translateX(2px)}
179.fd-gmc-pp svg:last-child{opacity:0;transform:scale(0.6)}
180.fd-gmc-pp.is-playing svg:first-child{opacity:0;transform:translateX(2px) scale(0.6)}
181.fd-gmc-pp.is-playing svg:last-child{opacity:1;transform:none}
182.fd-gmc-bar{display:flex;align-items:center;gap:12px;width:100%;margin:0;padding:0}
183.fd-gmc-scrub{flex:1 1 auto;min-width:0;display:flex;align-items:center;gap:14px;height:52px;margin:0;padding:0 20px}
184.fd-gmc-vol{flex:0 0 200px;display:flex;align-items:center;gap:10px;height:52px;margin:0;padding:0 18px 0 8px}
185.fd-gmc-time{flex:none;min-width:40px;margin:0;padding:0;font:600 13px/1 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;font-variant-numeric:tabular-nums;color:rgba(255,255,255,0.92);text-align:center}
186.fd-gmc-mute{flex:none;display:grid;place-items:center;width:36px;height:36px;margin:0;padding:0;border:0;border-radius:50%;background:none;color:#fff;cursor:pointer;-webkit-appearance:none;appearance:none;transition:background-color var(--fd-dur-1) linear}
187.fd-gmc-mute:hover{background:rgba(255,255,255,0.12)}
188.fd-gmc-mute svg{display:block}
189.fd-gmc-mute:focus-visible,.fd-gmc-btn:focus-visible{outline:2px solid color-mix(in srgb,#0A84FF 70%,transparent);outline-offset:2px}
190.fd-gmc-track{position:relative;flex:1 1 auto;min-width:40px;height:28px;display:block;margin:0;padding:0}
191.fd-gmc-rail{position:absolute;left:0;right:0;top:50%;height:6px;margin:-3px 0 0;padding:0;display:block;border-radius:999px;background:rgba(255,255,255,0.28);overflow:hidden;transition:height var(--fd-dur-2) var(--fd-ease-out),margin var(--fd-dur-2) var(--fd-ease-out)}
192.fd-gmc-track.is-active .fd-gmc-rail{height:10px;margin-top:-5px}
193.fd-gmc-fill{position:absolute;left:0;top:0;bottom:0;width:calc(var(--p) * 100%);display:block;margin:0;padding:0;background:#fff;border-radius:inherit}
194.fd-gmc-knob{position:absolute !important;top:50%;left:calc(var(--p) * (100% - 22px));width:22px;height:22px;margin:-11px 0 0;padding:0;display:block;pointer-events:none;
195 transform:scale(calc(0.55 + var(--fd-gmc-k,0) * 0.95));--fd-lg-shadow:0 2px 6px rgba(0,0,0,0.3)}
196.fd-gmc-knob-solid{position:absolute;inset:0;display:block;margin:0;padding:0;border-radius:inherit;background:#fff;opacity:calc(1 - var(--fd-gmc-k,0) * 1.15)}
197.fd-gmc-knob .fd-lg-spec{opacity:var(--fd-gmc-k,0)}
198.fd-gmc-input{position:absolute;inset:-8px 0;width:100%;height:calc(100% + 16px);margin:0;padding:0;border:0;opacity:0;cursor:pointer;-webkit-appearance:none;appearance:none;background:none}
199.fd-gmc-track:has(.fd-gmc-input:focus-visible) .fd-gmc-rail{box-shadow:0 0 0 2px color-mix(in srgb,#0A84FF 70%,transparent)}
200@media (max-width:640px){
201 .fd-gmc-bar{flex-direction:column;align-items:stretch}
202 .fd-gmc-vol{flex:none}
203 .fd-gmc-transport{gap:16px}
204}
205@media (prefers-reduced-motion: reduce){.fd-gmc-pp svg{transition-duration:120ms;transform:none !important}}
206`;
207
208/* ───────────────────────── demo ───────────────────────── */
209
210const DURATION = 7 * 60 + 42;
211
212export function Demo() {
213 const [playing, setPlaying] = useState(false);
214 const [time, setTime] = useState(134);
215 const [volume, setVolume] = useState(0.72);
216 const [muted, setMuted] = useState(false);
217
218 // play clock
219 useEffect(() => {
220 if (!playing) return;
221 const id = window.setInterval(() => setTime((t) => (t + 1 >= DURATION ? 0 : t + 1)), 1000);
222 return () => window.clearInterval(id);
223 }, [playing]);
224
225 return (
226 <div className="fd-gmcd">
227 <style>{demoCss}</style>
228 <div className="fd-gmcd-box">
229 <GlassMediaControls
230 title="Now playing"
231 playing={playing}
232 onPlayingChange={setPlaying}
233 time={time}
234 duration={DURATION}
235 onSeek={setTime}
236 volume={volume}
237 onVolumeChange={setVolume}
238 muted={muted}
239 onMutedChange={setMuted}
240 />
241 </div>
242 </div>
243 );
244}
245
246const F = `ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif`;
247
248const demoCss = `
249.fd-gmcd,.fd-gmcd *,.fd-gmcd *::before,.fd-gmcd *::after{box-sizing:border-box}
250.fd-gmcd{display:flex;align-items:center;justify-content:center;min-height:100vh;width:100%;margin:0;padding:32px 20px;overflow:hidden;color:#1d1d1f;font:400 15px/1.4 ${F};letter-spacing:normal;
251 background:radial-gradient(46% 62% at 28% 32%,#ff9f73 0%,transparent 72%),radial-gradient(44% 58% at 74% 68%,#7d8cff 0%,transparent 72%),radial-gradient(30% 40% at 62% 22%,#ff86b8 0%,transparent 72%),#d9d2dc}
252.fd-gmcd-box{width:min(100%,460px);margin:0;padding:0}
253`;

More Liquid Glass. Same file contract.

Liquid Glass, liquid glass preview: Liquid Glass for React: a lens that refracts what is behind it, with squircle bevel, specular rim, dispersion…

Liquid Glass

Liquid Glass for React: a lens that refracts what is behind it, with squircle bevel, specular rim, dispersion and spring physics.

Glass Button, liquid glass preview: Liquid Glass button for React: glass, prominent, clear and clear-prominent capsules in four sizes, with a…

Glass Button

Liquid Glass button for React: glass, prominent, clear and clear-prominent capsules in four sizes, with a springy press.

Glass Tab Bar, liquid glass preview: iOS 26 style Liquid Glass tab bar: a lens springs between tabs, search sits apart, and the bar minimizes as…

Glass Tab Bar

iOS 26 style Liquid Glass tab bar: a lens springs between tabs, search sits apart, and the bar minimizes as you scroll.

Questions about Glass Media Controls

Run npx shadcn@latest add https://freedesignmd.com/r/glass-media-controls.json, or open the page and copy the files into your project. It has zero dependencies besides React. What you copy is the exact file that renders the live demo.

Liquid Glass media controls over video: transport, scrubber and volume capsules, with the HIG 35% dimming layer. It is a free, MIT-licensed React liquid glass component from the freedesignmd library.

Yes. It is free and MIT-licensed, use, modify and ship it in personal and commercial projects without attribution.

Real refraction (SVG displacement inside backdrop-filter) in Chromium browsers. Safari and Firefox fall back to a frosted blur with the same rim and highlights.

Yes. It is a plain React component with its own styles, so it runs in Next.js, Vite, Remix and Lovable projects, and it needs no Tailwind setup. It has zero dependencies besides React.