Skip to content
All articles Tutorials

Add Liquid Glass with Vanilla JavaScript

Mount the QuickLiquid engine on an existing DOM element, tune it, and clean it up.

LiquidGlassEngine takes an existing HTMLElement and a configuration object. You can use it in a page with plain JavaScript, a server-rendered site, or a component system with a mount and unmount lifecycle.

Give the engine a real DOM element

Install quick-liquid in a project with a bundler such as Vite. Add an element with visible dimensions and place it over a patterned or photographic background.

<section class="scene">
  <article id="glass-card" style="padding: 1.5rem">
    <h2>Reading list</h2>
    <p>Three saved articles</p>
  </article>
</section>
import { LiquidGlassEngine } from 'quick-liquid';

export function attachGlassCard() {
  const card = document.getElementById('glass-card');
  if (!card) return;

  const glass = new LiquidGlassEngine(card, {
    material: 'regular',
    borderRadius: 20,
    refractionMode: 'auto',
  });

  glass.updateConfig({ refractionStrength: 18 });
  return () => glass.destroy();
}

Call attachGlassCard() after the markup exists. For a simple static page, a module script can call it once. In a client router, hold on to the returned cleanup function and call it when that view is removed. The engine owns observers, listeners, and DOM layers tied to the host. One engine per mounted element keeps that lifecycle easy to follow.

Patch the settings or replace them

updateConfig merges your change into the current overrides. setConfig replaces the overrides, allowing omitted properties to return to the selected material or default. For example, glass.setConfig({ material: 'clear' }) removes the previous explicit refraction strength so the clear preset can supply its own.

Keep application state in your own code and use the engine to display the visual effect. For a live reference with the same config fields, see the QuickLiquid documentation.