Tutorials
Liquid Glass in React and Next.js: A Reusable Component (No Library Needed)
Build a reusable liquid glass component for React and Next.js in about 40 lines: unique SVG filter ids with useId, SSR-safe browser detection, CSS fallbacks, plus an honest comparison of the popular libraries and React Native options.

In short: To use liquid glass in React, render an SVG displacement filter with a unique id from useId, apply a frosted CSS base, and switch on backdrop-filter refraction only in Chromium after the component mounts. That avoids hydration mismatches in Next.js and keeps a clean fallback in Safari and Firefox.
You can get liquid glass into a React app in two ways: install a library, or write a small component yourself. A library is faster to start with. Your own component is smaller, has no dependency to audit, and you control exactly how it falls back in Safari and Firefox.
This guide builds the component, explains the React-specific details that trip people up (filter ids, server rendering, hydration), and compares the main libraries honestly. We tested the code with React 19 and esbuild in Chromium.
How liquid glass works in a React app
React doesn’t change the technique. A liquid glass surface is still:
- a frosted base in CSS (
backdrop-filter: blur() saturate()), which works in every modern browser, - a light rim made with a masked gradient,
- an SVG displacement filter referenced from
backdrop-filter: url(#id), which bends the background at the edges. Only Chromium-based browsers render it.
React adds three problems to solve: each component instance needs a unique filter id, browser detection must not break server rendering, and the user’s accessibility settings must still win over anything you set from JavaScript. If the technique itself is new to you, start with the liquid glass CSS guide.
The component
Create LiquidGlass.jsx. The MAP constant is the URL-encoded displacement map from the CSS guide, shortened here for readability:
'use client';
import { useEffect, useId, useState } from 'react';
// Edge displacement map (see the liquid glass CSS guide for the readable version)
const MAP = "data:image/svg+xml,%3Csvg …%3C/svg%3E";
function useChromium() {
const [ok, setOk] = useState(false);
useEffect(() => {
setOk(Boolean(navigator.userAgentData?.brands?.some((b) => b.brand === 'Chromium')));
}, []);
return ok;
}
export default function LiquidGlass({
as: Tag = 'div',
strength = 0.18,
className = '',
style,
children,
...rest
}) {
const id = 'lg-' + useId().replace(/[^a-zA-Z0-9_-]/g, '');
const refract = useChromium();
return (
<>
<svg width="0" height="0" style={{ position: 'absolute' }} aria-hidden="true" focusable="false">
<filter id={id} x="0" y="0" width="1" height="1"
primitiveUnits="objectBoundingBox" colorInterpolationFilters="sRGB">
<feImage href={MAP} x="0" y="0" width="1" height="1"
preserveAspectRatio="none" result="map" />
<feDisplacementMap in="SourceGraphic" in2="map" scale={-strength}
xChannelSelector="R" yChannelSelector="G" />
</filter>
</svg>
<Tag
className={['glass', refract && 'glass--refract', className].filter(Boolean).join(' ')}
style={{ ...style, '--lg-filter': `url(#${id})` }}
{...rest}
>
{children}
</Tag>
</>
);
}
What each part does
| Piece | Why it’s there |
|---|---|
'use client' | Required in the Next.js App Router, because the component uses state and effects. It’s ignored by other setups. |
useId() | Gives each instance its own filter id, so two glass panels never fight over #lens. The regex strips the characters React adds, which differ between React versions. |
useChromium() in useEffect | Detection runs only in the browser, after hydration. The server and the first client render produce identical HTML, so there’s no hydration mismatch warning. |
--lg-filter custom property | Passes the filter reference to CSS instead of setting backdropFilter inline. Inline styles beat media queries, which would break the reduced-transparency fallback. |
as prop | Renders a nav, button, section or any other element, so the semantics stay correct. |
strength prop | Displacement scale: 0.08 is subtle, 0.3 is dramatic. |
The stylesheet
Create liquid-glass.css and import it once (in Next.js, in app/layout.jsx or the component file):
.glass {
position: relative;
isolation: isolate;
box-sizing: border-box;
padding: 28px;
border-radius: 28px;
color: #fff;
background: rgb(255 255 255 / .10);
-webkit-backdrop-filter: blur(12px) saturate(160%);
backdrop-filter: blur(12px) saturate(160%);
box-shadow:
inset 0 1px 0 rgb(255 255 255 / .55),
inset 0 -1px 0 rgb(255 255 255 / .12),
0 10px 30px rgb(0 0 0 / .25);
}
.glass::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
padding: 1.5px;
background: linear-gradient(135deg, rgb(255 255 255 / .8), transparent 40% 60%, rgb(255 255 255 / .35));
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
-webkit-mask-composite: xor;
mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
pointer-events: none;
}
.glass--refract {
-webkit-backdrop-filter: var(--lg-filter) blur(2px) saturate(160%);
backdrop-filter: var(--lg-filter) blur(2px) saturate(160%);
}
@media (prefers-reduced-transparency: reduce) {
.glass, .glass--refract {
background: rgb(20 22 30 / .92);
-webkit-backdrop-filter: none;
backdrop-filter: none;
}
}
The refraction lives in the .glass--refract class, and the media query switches it off. A user who asked their OS for less transparency gets a solid panel even in Chrome.
Using it
import LiquidGlass from './LiquidGlass';
import './liquid-glass.css';
export default function Hero() {
return (
<section className="hero">
<LiquidGlass style={{ maxWidth: 340 }}>
<h2>Liquid glass</h2>
<p>A reusable React component.</p>
</LiquidGlass>
<LiquidGlass as="nav" aria-label="Main" strength={0.24}>
<a href="/">Home</a> <a href="/docs">Docs</a>
</LiquidGlass>
</section>
);
}
In Chromium the stripes behind each panel bend at the rim and the centre stays flat and readable. In Safari and Firefox the same panels render as polished frosted glass, with nothing broken.
Next.js notes
- App Router: keep
'use client'at the top of the component. Server Components can render it as a child without becoming client components themselves. - No
useLayoutEffect: detection inuseEffectmeans the refraction appears one frame after hydration. That’s invisible in practice and avoids server/client differences. - Static export and ISR: nothing here depends on the request, so the component works with
output: 'export'and cached pages. - CSS Modules: if you use them, rename the classes and keep the media query in the same module.
Buttons and interaction states
For buttons, render the component as="button" and add hover, pressed and focus styles to the CSS. Our liquid glass button tutorial has tested CSS for every state, including a pill-shaped displacement map that suits rounded buttons better than the card map used here.
Liquid glass React libraries compared
If you’d rather install something, these are the options developers mention most often. Check each repository for its current state before you commit to it:
| Option | Approach | Safari / Firefox | Notes |
|---|---|---|---|
| Your own component (this guide) | CSS + SVG filter | Frosted fallback you control | ~40 lines, no dependency, any styling system |
liquid-glass-react | SVG displacement with mouse-reactive elasticity | The README says displacement isn’t visible there | MIT, popular on GitHub, many props (displacementScale, blurAmount, aberrationIntensity, elasticity, mode) |
| WebGL-based libraries | Render the glass with shaders on a canvas | Refraction can work everywhere | Heavier, and must capture what is behind the glass, which is hard with live DOM content |
| UIGlass export | Generated CSS + SVG filter + React wrapper | Frosted fallback or Scene mode | Visual editor, exports React, Vue, Tailwind and plain CSS |
The library approach makes sense when you want the mouse-reactive “elastic” behaviour out of the box. The component approach makes sense when you care about bundle size, design control and predictable fallbacks.
React Native is a different story
In React Native you aren’t rendering HTML, so backdrop-filter and SVG filters don’t apply. On iOS 26 and later you can use Apple’s native material through a native module. Callstack’s @callstack/liquid-glass, for example, provides a LiquidGlassView with regular and clear effects, an interactive mode and a container that lets nearby glass shapes merge. On older iOS versions and on Android it renders a normal view, so provide a translucent fallback background. For the design rules behind the native material, read Apple Liquid Glass explained.
Accessibility checklist
- Use the
asprop to keep real semantics:navfor navigation,buttonfor actions, never a clickablediv. - Check text contrast over the busiest part of the background (4.5:1 for body text).
- Keep a visible focus style on interactive glass.
- Honour
prefers-reduced-transparency,prefers-contrastandprefers-reduced-motion. The accessible glass UI guide has the full set.
Frequently asked questions
How do I add a liquid glass effect in React?
Wrap your content in a component that renders an SVG displacement filter with a unique id from useId(), apply a frosted CSS base, and enable backdrop-filter: url(#id) only in Chromium browsers after mount. The complete component is above.
Why do I get a hydration mismatch with liquid glass in Next.js?
Usually because browser detection runs during render, so the server (no browser) and the client produce different markup. Move detection into useEffect, as in this component, and the first client render matches the server.
Why does the effect only work in Chrome?
Only Chromium-based browsers render SVG filters inside backdrop-filter. Safari and Firefox show the frosted fallback. To get refraction there you need a different technique, such as copying the background into the element and filtering that copy, which UIGlass offers as Scene mode.
Can I use liquid glass with Tailwind in React?
Yes. Keep the component and replace the stylesheet with Tailwind utilities (backdrop-blur, bg-white/10, shadow-[inset_…]), plus one custom class or an arbitrary property for the url() filter, since Tailwind has no built-in utility for SVG backdrop filters. The Tailwind liquid glass guide has the full setup, and the UIGlass builder can export Tailwind classes directly.
Does liquid glass work in React Native?
Not with web CSS. On iOS 26+ use a native module that wraps Apple’s Liquid Glass material, and provide a translucent fallback for Android and older iOS.
Is there an npm package for liquid glass in React?
Yes. liquid-glass-react is a popular MIT-licensed package with props for displacement, blur, aberration and elasticity. Its README notes that displacement isn’t visible in Safari and Firefox.
How do I use liquid glass in Next.js?
Mark the component with 'use client', generate the filter id with useId, and run browser detection in useEffect. Server and client then render the same HTML, and refraction switches on after hydration.
Why should each glass component have its own filter id?
Two components sharing an id such as #lens can pick up the wrong displacement map, so one of them refracts with the wrong shape. useId gives every instance a unique id.
Can I use liquid glass with Vue or Svelte?
Yes. The technique is the same in any framework: render the SVG filter with a unique id, apply the frosted CSS, and add refraction in Chromium after mount. The UIGlass builder also exports Vue.


