Create Modern Glassmorphism Interfaces with Liquid Glass CSS Framework

Category: Frameworks , Javascript | December 25, 2025
AuthorMael-667
Last UpdateDecember 25, 2025
LicenseMIT
Tags
Views167 views
Create Modern Glassmorphism Interfaces with Liquid Glass CSS Framework

Liquid Glass CSS is a lightweight JavaScript/CSS library that applies an Apple-style, refractive, liquid glass effect with liquid distortion to HTML elements.

Features:

  • SVG Displacement Filters: Uses feTurbulence and feDisplacementMap to create the organic “liquid” refraction.
  • Utility Class API: Apply effects with classes like .liquidGlass, .liquidGlassLarge, .liquidBtn, and .blur-[0-10].
  • Dynamic Color Tinting: Elements can inherit hue from their surroundings via data-hue attributes and the .dynamicHue class.
  • Light Mode Support: The .glassLightMode modifier switches text to black and removes depth shadows for bright backgrounds.

How To Use It:

1. Load the Liquid Glass CSS’ JavaScript in the document. The script listens for DOMContentLoaded, then appends an inline <style> block to the <head> and an invisible <svg> containing the displacement filters to the <body>.

<script src="./liquidGlass.js"></script>

2. Add the .liquidGlass class to any element:

<!-- Basic frosted glass card -->
<div class="liquidGlass" style="padding: 2rem;">
  <h2>Welcome</h2>
  <p>This card has the Liquid Glass effect applied.</p>
</div>

3. When your glass element sits on a white or light-colored background, add .glassLightMode:

<!-- Glass card optimized for light backgrounds -->
<div class="liquidGlass glassLightMode" style="padding: 2rem;">
  <p>Black text, no heavy shadows — cleaner on light surfaces.</p>
</div>

4. For modals, hero overlays, or full-width sections, use .liquidGlassLarge:

<!-- Large glass panel with 3rem border-radius -->
<section class="liquidGlassLarge" style="padding: 4rem;">
  <h1>Feature Showcase</h1>
  <p>This variant removes saturation to avoid visual distraction on big areas.</p>
</section>

5. Use .blur-[0-10] to override the default 3px blur:

<!-- Heavy blur (10px) -->
<div class="liquidGlass blur-10" style="padding: 1rem;">
  Maximum frost effect.
</div>
<!-- No blur -->
<div class="liquidGlass blur-0" style="padding: 1rem;">
  Distortion only, no frosting.
</div>

6. The .liquidBtn class styles buttons with a translucent background and hover transitions:

<!-- Frosted glass button -->
<button class="liquidBtn">
  Get Started
</button>

7. Enable Dynamic Color Tinting. This feature lets .liquidGlass elements change their tint based on the data-hue of background sections they overlap.

Add data-hue="#hexcolor" to content sections:

<!-- Define hue zones -->
<section data-hue="#4169e1" style="height: 100vh; background: #4169e1;">
  <h2>Royal Blue Zone</h2>
</section>
<section data-hue="#e14169" style="height: 100vh; background: #e14169;">
  <h2>Pink Zone</h2>
</section>

Wrap your glass elements in a parent with .dynamicHue or .dynamicHueHvr:

<!-- Sticky nav that tints based on scroll position -->
<nav class="dynamicHueHvr" style="position: fixed; top: 0; width: 100%;">
  <div class="liquidGlass" style="padding: 1rem;">
    Navigation Bar
  </div>
</nav>

8. Override Background Color and Shadows.

/* Custom dark glass with stronger shadow */
.my-custom-glass::after {
  background: rgb(0 0 0 / 15%);
  box-shadow:
    inset 1px 1px 3px #ffffff,        /* Inner highlight */
    inset -1px -2px 3px #3131314d,    /* Inner shadow */
    0px 0px 12px #00000075;           /* Outer glow */
}

9. Override Border Radius. You must apply the radius to the element and both pseudo-elements:

/* Sharper corners */
.my-custom-glass,
.my-custom-glass::before,
.my-custom-glass::after {
  border-radius: 0.25rem;
}

CSS Classes Reference

ClassDescription
.liquidGlassCore frosted glass effect. White text, 0.9rem radius, 3px blur, depth shadows.
.glassLightModeModifier for light backgrounds. Black text, no depth shadows.
.liquidGlassLargeVariant for large surfaces. 3rem radius, no saturation boost.
.liquidBtnFrosted button style. Translucent white background, hover transition.
.blur-0Sets backdrop-filter: blur(0px).
.blur-1Sets backdrop-filter: blur(1px).
.blur-2Sets backdrop-filter: blur(2px).
.blur-3Sets backdrop-filter: blur(3px) (default).
.blur-4Sets backdrop-filter: blur(4px).
.blur-5Sets backdrop-filter: blur(5px).
.blur-6Sets backdrop-filter: blur(6px).
.blur-7Sets backdrop-filter: blur(7px).
.blur-8Sets backdrop-filter: blur(8px).
.blur-9Sets backdrop-filter: blur(9px).
.blur-10Sets backdrop-filter: blur(10px).
.dynamicHueParent class. Enables scroll-based color tinting for child .liquidGlass elements.
.dynamicHueHvrParent class. Same as .dynamicHue, plus hover state color shift.
.dynamicAuto-applied by JavaScript when a glass element overlaps a data-hue zone.

Data Attributes Reference

AttributeDescription
data-hue="#hexcolor"Defines the tint color for a section. Glass elements with .dynamicHue parents will inherit this color when overlapping.

CSS Custom Properties (Set by JavaScript)

PropertyDescription
--backgroundBackground color applied to .dynamic::after.
--shadowBox shadow applied to .dynamic::after.
--backgroundHoverHover background color for .dynamicHueHvr children.

Changelog:

12/25/2025

  • v1.2

You Might Be Interested In:


Leave a Reply