Skip to Content
Liquid Glass UI

Liquid Glass Opacity

Provides a reusable LiquidGlassProvider, useLiquidGlass hook, and Apple System Settings-style Clear ↔ Tinted opacity slider to control Liquid Glass translucency, frost, and contrast globally.

Modeled after Appearance → Liquid Glass in Apple iOS / macOS System Settings, we provide a standalone LiquidGlassProvider, the useLiquidGlass() hook, and a ready-to-use LiquidGlassTintSlider control installable via the shadcn Registry.

  • Clear (tint = 0): Lower backdrop opacity and lighter frost so background colors and details shine through.
  • Regular (tint = 0.5): Balanced translucency and text legibility.
  • Default (tint = 0.75): Between Regular and Tinted — the initial value on first visit or when used without a Provider, offering stronger contrast for text and controls.
  • Tinted (tint = 1): Higher glass opacity and softer frost to boost contrast for content and controls over complex backgrounds.

Interactive Demo: Clear ↔ Tinted

Drag the slider below (or the global Glass Opacity slider in the sidebar footer) to update every Button, Tabs, Select, and glass surface across the site in real time:

apple-liquid-ui/preview/liquid-glass-settings
MacBook · 16:10

Installation (Shadcn Registry)

# Install Provider, Hook, and built-in slider via the @apple-liquid namespace
npx shadcn@latest add @apple-liquid/liquid-glass-provider

# Or install directly via URL
npx shadcn@latest add https://your-domain.com/r/liquid-glass-provider.json

All components render normally even without wrapping <LiquidGlassProvider> via the default CSS token (--liquid-glass-tint: 0.75). Wrapping with the provider unlocks runtime global switching, localStorage persistence, and built-in multi-language localization via locale.

Usage in Your Project

1. Wrap your root layout with LiquidGlassProvider

// app/layout.tsx
import { LiquidGlassProvider } from '@/components/ui/liquid-glass-provider';

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <LiquidGlassProvider defaultTint="regular" locale="en">
          {children}
        </LiquidGlassProvider>
      </body>
    </html>
  );
}

2. Drop in the built-in slider or use useLiquidGlass()

'use client';

import { Button } from '@/components/ui/button';
import {
  LiquidGlassTintSlider,
  useLiquidGlass,
} from '@/components/ui/liquid-glass-provider';

export function AppearanceSettings() {
  const { tint, preset, setPreset, resetTint } = useLiquidGlass();

  return (
    <div className="space-y-4">
      {/* Ready-to-use Apple System Settings-style slider */}
      <LiquidGlassTintSlider showDescription />

      {/* Or bind custom buttons / presets via the hook */}
      <div className="flex flex-wrap items-center gap-2">
        <Button size="sm" variant="secondary" onClick={() => setPreset('clear')}>Clear</Button>
        <Button size="sm" variant="secondary" onClick={() => setPreset('regular')}>Regular</Button>
        <Button size="sm" variant="secondary" onClick={() => setPreset('tinted')}>Tinted</Button>
        <Button size="sm" variant="ghost" onClick={resetTint}>
          Reset ({Math.round(tint * 100)}% / {preset})
        </Button>
      </div>
    </div>
  );
}

Local Tint & Accent

Tint and accent follow the same global / local model as the other settings. The outermost <LiquidGlassProvider> is global and writes them onto :root. To give one region its own values (for example, comparing Clear and Tinted side by side), wrap it in <LiquidGlassConfig tint accent>. Overlays opened inside the region (Popover, Select, Dialog, Drawer…) are portaled to <body> but keep the local values:

apple-liquid-ui/preview/liquid-glass-scoped-compare
MacBook · 16:10
<LiquidGlassConfig tint="clear">…</LiquidGlassConfig>
<LiquidGlassConfig tint={1} accent="purple">…</LiquidGlassConfig>

LiquidGlassConfig values are fixed (you control them). For a local tint the user can change with its own slider, nest a second <LiquidGlassProvider>: a nested provider is automatically local, so syncToRoot={false} is no longer needed.

Global Settings & Per-Component Overrides

<LiquidGlassProvider> sets the defaults every component inherits — locale, messages, glass and disableMotion — and every component can override them with its own props. Highest priority first:

  1. The component's own prop: glass, disableMotion, locale, messages.
  2. The nearest enclosing scope: an opaque (glass={false}) surface or group, an enclosing component's locale / messages (they also reach its parts and the overlays it opens), or <LiquidGlassConfig>.
  3. <LiquidGlassProvider>: glass, disableMotion, locale, messages.
  4. Built-in defaults: glass material (always with edge refraction), animations on, English text. The OS "reduce motion" preference always turns animations off.
SettingGlobalPer component
locale<LiquidGlassProvider locale="ja"><Select locale="ja">
messagesmessages={{ select: { title: '…' } }}, keyed by component<Select messages={{ title: '…' }}>
glass<LiquidGlassProvider glass={false}> renders every component opaque<Button glass> / <Card glass={false}>
disableMotion<LiquidGlassProvider disableMotion> turns off the Motion spring animations<Switch disableMotion={false}>
tint / accentOutermost <LiquidGlassProvider> (defaultTint / accent, written to :root)<LiquidGlassConfig tint accent> for a region, or a nested provider
apple-liquid-ui/preview/liquid-glass-config
MacBook · 16:10
<LiquidGlassProvider
  locale="zh-CN"
  glass={false}
  messages={{
    select: { title: 'Pick one' },
    dataTable: { empty: 'No records' },
  }}
>
  <Select>…</Select> {/* Pick one · opaque */}
  <Select locale="ja">…</Select> {/* Japanese text */}
  <Dialog messages={{ close: 'Dismiss' }}>…</Dialog> {/* Only this dialog */}
  <Button glass>Glass</Button> {/* Own prop wins: glass */}
</LiquidGlassProvider>

Settings passed to a component reach everything it renders: its parts, its children, the components it uses internally and the overlays it opens. <Card glass={false}> makes a Popover opened from it opaque too, and <DataTable locale="ja"> translates its internal Select and buttons too.

Text overrides are deep-merged: built-in text for the language → global messages.<key> → the component's messages, so you only list the labels you change.

Custom Languages

Language tags that are not built in (e.g. vi) render the English text; supply the language through messages. Each component exports its messages type (SelectMessages, DialogMessages, …) for type checking:

import type { DialogMessages } from '@/components/ui/dialog';
import type { SelectMessages } from '@/components/ui/select';
import type { LiquidGlassMessages } from '@/components/ui/liquid-glass-provider';

const vi = {
  select: { title: 'Chọn' } satisfies Partial<SelectMessages>,
  dialog: { close: 'Đóng', maximize: 'Phóng to', restore: 'Khôi phục' } satisfies DialogMessages,
} satisfies LiquidGlassMessages;

<LiquidGlassProvider locale="vi" messages={vi}>{children}</LiquidGlassProvider>

messages belong to the language they were written for: when a component or <LiquidGlassConfig> switches to another locale, the outer messages no longer apply there.

Scoped Settings (LiquidGlassConfig)

To change the settings for one region without a second provider (and without touching tint / accent), wrap it in <LiquidGlassConfig>; unset props inherit from outside:

import { LiquidGlassConfig } from '@/components/ui/liquid-glass-provider';

<LiquidGlassConfig locale="ar" glass={false}>
  {/* Arabic (RTL) text, opaque components */}
</LiquidGlassConfig>

Message Keys

KeyComponentsMessages type
liquidGlassLiquidGlassTintSlider / LiquidGlassAccentPickerLiquidGlassProviderMessages
breadcrumbBreadcrumbBreadcrumbMessages
carouselCarouselCarouselMessages
codeBlockCodeBlockCodeBlockMessages
colorPickerColorPickerColorPickerMessages
comboboxComboboxComboboxMessages
commandCommand / CommandDialogCommandMessages
contextMenuContextMenuContextMenuMessages
dialogDialogDialogMessages
dropdownMenuDropdownMenuDropdownMenuMessages
iconPickerIconPickerIconPickerMessages
messageScrollerMessageScrollerMessageScrollerMessages
navigationMenuNavigationMenuNavigationMenuMessages
paginationPaginationPaginationMessages
questionnaireQuestionnaireQuestionnaireMessages
selectSelectSelectMessages
sheetSheetSheetMessages
sidebarSidebarProviderSidebarMessages
spinnerSpinnerSpinnerMessages
toastToasterToastMessages
treeTree / TreeSelectTreeMessages
uploadUploadUploadMessages
dataTableDataTableDataTableMessages
filePreviewFilePreview / PreviewDialogFilePreviewMessages
filterPanelFilterPanelFilterPanelMessages
settingsSplitSettingsSplitSettingsSplitMessages
tiptapEditorTiptapEditor / TiptapContentRenderer / EditorToolbarTiptapEditorMessages

API Reference

LiquidGlassProvider

PropTypeDefaultDescription
defaultTintnumber | 'clear' | 'regular' | 'tinted'0.75Initial opacity (0 Clear, 1 Tinted)
tintnumber—Controlled opacity value (0–1)
onTintChange(tint: number) => void—Callback fired when opacity changes
localeLiquidGlassLocaleInput—Controlled UI language or BCP 47 tag (en, zh-CN, zh-TW, ja, ko, es, fr, de, pt, ru, it, ar); each component resolves its own built-in translations
defaultLocaleLiquidGlassLocaleInputOuter provider's, else 'en'Initial UI language when uncontrolled
onLocaleChange(locale: LiquidGlassLocale, tag: string) => void—Callback fired when the locale changes (tag keeps custom languages such as 'vi')
messagesLiquidGlassMessages—Global text overrides keyed by component ({ select: { … }, dataTable: { … } }); a component's own messages wins
glassbooleantrueDefault material for every component that leaves glass unset; false renders them all opaque. A component's own glass wins
disableMotionbooleanfalseTurns off the Motion spring animations (press scale, liquid indicators, menu transitions) of every component that leaves disableMotion unset. A component's own disableMotion wins; the OS "reduce motion" preference always applies
storageKeystring | false'apple-liquid-ui:glass-tint'localStorage persistence key; pass false to disable
syncToRootbooleantrue outermost, false nestedWhether tint & accent go to :root (global) or to the provider's subtree and its overlays (local). Detected automatically; rarely needed

useLiquidGlass()

Return FieldTypeDescription
tintnumberCurrent opacity value (0–1)
setTint(next: number | LiquidGlassPreset) => voidSet opacity continuously or jump to a preset
preset'clear' | 'regular' | 'tinted' | 'custom'Active preset name
setPreset(preset: LiquidGlassPreset) => voidJump directly to a named preset
resetTint() => voidReset back to defaultTint
localeLiquidGlassLocaleActive normalized locale (also readable via useLiquidGlassLocale())
localeTagstringThe language tag as given (e.g. 'vi'), also via useLiquidGlassLocaleTag()
setLocale(next: LiquidGlassLocaleInput) => voidSwitch UI language at runtime

LiquidGlassTintSlider

PropTypeDefaultDescription
compactbooleanfalseCompact layout for sidebars and toolbars
showDescriptionbooleanfalseShow the Apple Settings explanatory description below
showLabelbooleantrueShow the header title and current percentage/preset badge
labelReact.ReactNode'Liquid Glass Opacity'Custom header label
localeLiquidGlassLocaleInput—UI language of this slider; overrides the global locale
messagesPartial<LiquidGlassProviderMessages>—Text overrides; merged over the global messages.liquidGlass

LiquidGlassConfig

PropTypeDefaultDescription
localeLiquidGlassLocaleInputInheritedUI language of the subtree
messagesLiquidGlassMessagesInheritedText overrides keyed by component, merged over the outer ones
glassbooleanInheritedDefault material of the subtree
disableMotionbooleanInheritedDefault disableMotion of the subtree
tintnumber | 'clear' | 'regular' | 'tinted'InheritedFixed glass tint of the subtree and its overlays
accentLiquidGlassAccentInheritedAccent color of the subtree and its overlays

Hooks for Custom Components

HookReturnsDescription
useLiquidGlassLocale()LiquidGlassLocaleActive built-in locale (component locale → LiquidGlassConfig → provider)
useLiquidGlassLocaleTag()stringActive language tag as given, for Intl formatting
useLiquidGlassTranslation(key, table, { locale, messages }?)TYour component's text: table[locale] deep-merged with the global messages[key] and the component's own props
useInheritedGlass(glass?)booleanResolves a glass prop: own value → enclosing surface → global glass → true (from liquid-surface)
useLiquidReducedMotion(disableMotion?)booleantrue when animations should be skipped: own disableMotion → global setting, or the OS "reduce motion" preference
useLiquidGlassPortalProps()objectSpread onto a custom portal container (<XxxPrimitive.Portal {...props}>) so overlays keep a local tint / accent

On this page