dashersw/liquid-glass-js

Liquid Glass UI - Apple-Inspired Glass Effects Library

JavaScript

1,198

1 commits

updated Jun 12, 2025

See the code

See what people are saying

SourceMessageScoreDate

Liquid Glass UI-Inspired Glass Effects Library

2

Sep 28, 2026

README

๐ŸŽ Liquid Glass JS

Apple Liquid Glass-inspired glass effects for the web

A WebGL-powered library bringing sophisticated glass JS components with real-time refraction, blur, and masking

๐ŸŒ Live Demo | ๐Ÿ“š Documentation | ๐Ÿš€ Quick Start

Demo

License: MIT JavaScript WebGL


โœจ Features

  • ๐ŸŽฏ Three Shape Types: Rounded rectangles, perfect circles, and pill/capsule shapes
  • ๐Ÿ” Real-time Refraction: Advanced WebGL shaders with multi-layer glass effects
  • ๐ŸŒŠ Nested Glass System: Child elements sample parent container outputs
  • โšก Live Parameter Control: Real-time adjustment of all glass properties
  • ๐Ÿ“ฑ Responsive Design: Automatic sizing and viewport adaptation
  • ๐ŸŽจ Customizable Tinting: Per-instance opacity and gradient control
  • ๐ŸŒ Cross-browser: Modern browser support with WebGL
  • ๐Ÿ“ฆ Zero Dependencies: Pure JavaScript (except html2canvas for page sampling)

๐Ÿš€ Quick Start

Basic Usage

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="styles.css" />
    <link rel="stylesheet" href="glass.css" />
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
    <script src="container.js"></script>
    <script src="button.js"></script>

    <script>
      // Create a glass button
      const button = new Button({
        text: 'Click Me!',
        size: 32,
        type: 'rounded',
        onClick: () => alert('Hello Glass!')
      })

      document.body.appendChild(button.element)
    </script>
  </body>
</html>

Container with Nested Glass

// Create a glass container
const container = new Container({
  borderRadius: 24,
  type: 'pill',
  tintOpacity: 0.3
})

// Add glass buttons to container
const button1 = new Button({
  text: 'Action',
  size: 24,
  type: 'pill'
})

const button2 = new Button({
  text: 'โœ“',
  size: 24,
  type: 'circle'
})

container.addChild(button1)
container.addChild(button2)
document.body.appendChild(container.element)

๐Ÿ“š API Reference

Container Class

Constructor Options

OptionTypeDefaultDescription
borderRadiusnumber48Corner radius in pixels
typestring'rounded'Shape type: 'rounded', 'circle', or 'pill'
tintOpacitynumber0.2Tint overlay opacity (0-1)

Methods

// Add child element (enables nested glass)
container.addChild(childElement)

// Remove child element
container.removeChild(childElement)

// Force size update from DOM
container.updateSizeFromDOM()

Button Class

Extends Container with button-specific functionality.

Constructor Options

OptionTypeDefaultDescription
textstring'Button'Button text content
sizenumber48Font size in pixels
typestring'rounded'Shape type: 'rounded', 'circle', or 'pill'
onClickfunctionnullClick event handler
warpbooleanfalseEnable center distortion effect
tintOpacitynumber0.2Tint overlay opacity (0-1)

Example

const button = new Button({
  text: 'Save Changes',
  size: 28,
  type: 'pill',
  tintOpacity: 0.4,
  warp: true,
  onClick: text => {
    console.log(`${text} was clicked!`)
  }
})

๐ŸŽ›๏ธ Glass Effect Parameters

The library provides fine-grained control over glass rendering:

ParameterRangeDescription
Edge Intensity0-0.1Refraction strength at shape edges
Rim Intensity0-0.2Intensity of rim lighting effects
Base Intensity0-0.05Center distortion strength
Edge Distance0.05-0.5Falloff curve for edge effects
Rim Distance0.1-2.0Falloff curve for rim effects
Base Distance0.05-0.3Falloff curve for base effects
Corner Boost0-0.1Additional corner enhancement
Ripple Effect0-0.5Surface texture simulation
Blur Radius1-15Background blur amount
Tint Opacity0-1.0Gradient overlay strength

๐Ÿ”ง Advanced Usage

Custom Glass Controls

// Global glass parameters
window.glassControls = {
  edgeIntensity: 0.02,
  rimIntensity: 0.08,
  blurRadius: 7.0,
  tintOpacity: 0.3
}

// Update all instances
function updateAllGlassInstances() {
  Container.instances.forEach(instance => {
    if (instance.gl_refs && instance.gl_refs.gl) {
      const gl = instance.gl_refs.gl
      gl.uniform1f(instance.gl_refs.edgeIntensityLoc, window.glassControls.edgeIntensity)
      // ... update other uniforms
      if (instance.render) instance.render()
    }
  })
}

Shape Types

Rounded Rectangle

const rounded = new Button({
  type: 'rounded',
  borderRadius: 16 // Custom radius
})

Perfect Circle

const circle = new Button({
  type: 'circle',
  size: 32 // Determines circle diameter
})

Pill/Capsule

const pill = new Button({
  type: 'pill',
  text: 'Elongated Button' // Auto-sizing
})

๐ŸŽจ Styling

CSS Classes

The library provides semantic CSS classes:

/* Glass containers */
.glass-container {
  /* Base container styles */
}
.glass-container-circle {
  /* Circle-specific styles */
}
.glass-container-pill {
  /* Pill-specific styles */
}

/* Glass buttons */
.glass-button {
  /* Base button styles */
}
.glass-button-circle {
  /* Circle button styles */
}
.glass-button-text {
  /* Button text overlay */
}

Custom Themes

/* Dark theme example */
.glass-button {
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
}

.glass-button-text {
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

๐Ÿ—๏ธ Architecture

WebGL Implementation

  • Multi-layer refraction: Separate edge, rim, and base calculations
  • Shape-aware normals: Different algorithms per shape type
  • Gaussian blur sampling: 13ร—13 adaptive kernel
  • Real-time page capture: html2canvas integration
  • Dynamic uniforms: Live parameter updates

File Structure

liquid-glass-js/
โ”œโ”€โ”€ container.js      # Core Container class
โ”œโ”€โ”€ button.js         # Button class (extends Container)
โ”œโ”€โ”€ demo.js          # Demo setup and controls
โ”œโ”€โ”€ styles.css       # Base styling
โ”œโ”€โ”€ glass.css        # Glass component styles
โ”œโ”€โ”€ demo.css         # Demo layout styles
โ”œโ”€โ”€ controls.css     # Control panel styles
โ””โ”€โ”€ index.html       # Demo page

๐ŸŒ Browser Support

BrowserVersionStatus
Chrome80+โœ… Full support
Firefox75+โœ… Full support
Safari14+โœ… Full support
Edge80+โœ… Full support

Requirements:

  • WebGL 2.0 support
  • ES6+ JavaScript features
  • HTML5 Canvas API

๐Ÿ› ๏ธ Development

Local Development

# Clone the repository
git clone https://github.com/your-username/liquid-glass-js.git
cd liquid-glass-js

# Open in browser (requires local server for WebGL)
# For example, using serve
npx serve .

Building

No build step required! The library uses vanilla JavaScript and can be used directly.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style
  • Add comments for complex WebGL operations
  • Test across different browsers
  • Update documentation for new features

๐Ÿ“– Examples

const navContainer = new Container({
  type: 'rounded',
  borderRadius: 20,
  tintOpacity: 0.1
})

;['Home', 'About', 'Contact'].forEach(text => {
  const navButton = new Button({
    text: text,
    size: 16,
    type: 'pill',
    onClick: text => navigate(text)
  })
  navContainer.addChild(navButton)
})

Control Panel

const controlPanel = new Container({
  type: 'rounded',
  borderRadius: 12,
  tintOpacity: 0.6
})

const playButton = new Button({
  text: 'โ–ถ',
  size: 24,
  type: 'circle',
  onClick: () => player.play()
})

controlPanel.addChild(playButton)

๐Ÿ”ฎ Roadmap

  • Bundle for NPM
  • TypeScript rewrite
  • React/Vue component wrappers
  • Animation system
  • Accessibility improvements
  • Performance optimizations
  • Mobile touch optimizations

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by Apple's Liquid Glass design language
  • WebGL techniques from various computer graphics resources
  • html2canvas library for page capture functionality

Built with โค๏ธ for the future of web interfaces

Demo โ€ข Issues โ€ข Discussions

Significant stargazers

Daniel Strobusch

19 followers ยท starred Sep 2025

dashersw/liquid-glass-js

Liquid Glass UI - Apple-Inspired Glass Effects Library

JavaScript

1,198

1 commits

updated Jun 12, 2025

See the code

See what people are saying

SourceMessageScoreDate

Liquid Glass UI-Inspired Glass Effects Library

2

Sep 28, 2026

README

๐ŸŽ Liquid Glass JS

Apple Liquid Glass-inspired glass effects for the web

A WebGL-powered library bringing sophisticated glass JS components with real-time refraction, blur, and masking

๐ŸŒ Live Demo | ๐Ÿ“š Documentation | ๐Ÿš€ Quick Start

Demo

License: MIT JavaScript WebGL


โœจ Features

  • ๐ŸŽฏ Three Shape Types: Rounded rectangles, perfect circles, and pill/capsule shapes
  • ๐Ÿ” Real-time Refraction: Advanced WebGL shaders with multi-layer glass effects
  • ๐ŸŒŠ Nested Glass System: Child elements sample parent container outputs
  • โšก Live Parameter Control: Real-time adjustment of all glass properties
  • ๐Ÿ“ฑ Responsive Design: Automatic sizing and viewport adaptation
  • ๐ŸŽจ Customizable Tinting: Per-instance opacity and gradient control
  • ๐ŸŒ Cross-browser: Modern browser support with WebGL
  • ๐Ÿ“ฆ Zero Dependencies: Pure JavaScript (except html2canvas for page sampling)

๐Ÿš€ Quick Start

Basic Usage

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="styles.css" />
    <link rel="stylesheet" href="glass.css" />
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
    <script src="container.js"></script>
    <script src="button.js"></script>

    <script>
      // Create a glass button
      const button = new Button({
        text: 'Click Me!',
        size: 32,
        type: 'rounded',
        onClick: () => alert('Hello Glass!')
      })

      document.body.appendChild(button.element)
    </script>
  </body>
</html>

Container with Nested Glass

// Create a glass container
const container = new Container({
  borderRadius: 24,
  type: 'pill',
  tintOpacity: 0.3
})

// Add glass buttons to container
const button1 = new Button({
  text: 'Action',
  size: 24,
  type: 'pill'
})

const button2 = new Button({
  text: 'โœ“',
  size: 24,
  type: 'circle'
})

container.addChild(button1)
container.addChild(button2)
document.body.appendChild(container.element)

๐Ÿ“š API Reference

Container Class

Constructor Options

OptionTypeDefaultDescription
borderRadiusnumber48Corner radius in pixels
typestring'rounded'Shape type: 'rounded', 'circle', or 'pill'
tintOpacitynumber0.2Tint overlay opacity (0-1)

Methods

// Add child element (enables nested glass)
container.addChild(childElement)

// Remove child element
container.removeChild(childElement)

// Force size update from DOM
container.updateSizeFromDOM()

Button Class

Extends Container with button-specific functionality.

Constructor Options

OptionTypeDefaultDescription
textstring'Button'Button text content
sizenumber48Font size in pixels
typestring'rounded'Shape type: 'rounded', 'circle', or 'pill'
onClickfunctionnullClick event handler
warpbooleanfalseEnable center distortion effect
tintOpacitynumber0.2Tint overlay opacity (0-1)

Example

const button = new Button({
  text: 'Save Changes',
  size: 28,
  type: 'pill',
  tintOpacity: 0.4,
  warp: true,
  onClick: text => {
    console.log(`${text} was clicked!`)
  }
})

๐ŸŽ›๏ธ Glass Effect Parameters

The library provides fine-grained control over glass rendering:

ParameterRangeDescription
Edge Intensity0-0.1Refraction strength at shape edges
Rim Intensity0-0.2Intensity of rim lighting effects
Base Intensity0-0.05Center distortion strength
Edge Distance0.05-0.5Falloff curve for edge effects
Rim Distance0.1-2.0Falloff curve for rim effects
Base Distance0.05-0.3Falloff curve for base effects
Corner Boost0-0.1Additional corner enhancement
Ripple Effect0-0.5Surface texture simulation
Blur Radius1-15Background blur amount
Tint Opacity0-1.0Gradient overlay strength

๐Ÿ”ง Advanced Usage

Custom Glass Controls

// Global glass parameters
window.glassControls = {
  edgeIntensity: 0.02,
  rimIntensity: 0.08,
  blurRadius: 7.0,
  tintOpacity: 0.3
}

// Update all instances
function updateAllGlassInstances() {
  Container.instances.forEach(instance => {
    if (instance.gl_refs && instance.gl_refs.gl) {
      const gl = instance.gl_refs.gl
      gl.uniform1f(instance.gl_refs.edgeIntensityLoc, window.glassControls.edgeIntensity)
      // ... update other uniforms
      if (instance.render) instance.render()
    }
  })
}

Shape Types

Rounded Rectangle

const rounded = new Button({
  type: 'rounded',
  borderRadius: 16 // Custom radius
})

Perfect Circle

const circle = new Button({
  type: 'circle',
  size: 32 // Determines circle diameter
})

Pill/Capsule

const pill = new Button({
  type: 'pill',
  text: 'Elongated Button' // Auto-sizing
})

๐ŸŽจ Styling

CSS Classes

The library provides semantic CSS classes:

/* Glass containers */
.glass-container {
  /* Base container styles */
}
.glass-container-circle {
  /* Circle-specific styles */
}
.glass-container-pill {
  /* Pill-specific styles */
}

/* Glass buttons */
.glass-button {
  /* Base button styles */
}
.glass-button-circle {
  /* Circle button styles */
}
.glass-button-text {
  /* Button text overlay */
}

Custom Themes

/* Dark theme example */
.glass-button {
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
}

.glass-button-text {
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

๐Ÿ—๏ธ Architecture

WebGL Implementation

  • Multi-layer refraction: Separate edge, rim, and base calculations
  • Shape-aware normals: Different algorithms per shape type
  • Gaussian blur sampling: 13ร—13 adaptive kernel
  • Real-time page capture: html2canvas integration
  • Dynamic uniforms: Live parameter updates

File Structure

liquid-glass-js/
โ”œโ”€โ”€ container.js      # Core Container class
โ”œโ”€โ”€ button.js         # Button class (extends Container)
โ”œโ”€โ”€ demo.js          # Demo setup and controls
โ”œโ”€โ”€ styles.css       # Base styling
โ”œโ”€โ”€ glass.css        # Glass component styles
โ”œโ”€โ”€ demo.css         # Demo layout styles
โ”œโ”€โ”€ controls.css     # Control panel styles
โ””โ”€โ”€ index.html       # Demo page

๐ŸŒ Browser Support

BrowserVersionStatus
Chrome80+โœ… Full support
Firefox75+โœ… Full support
Safari14+โœ… Full support
Edge80+โœ… Full support

Requirements:

  • WebGL 2.0 support
  • ES6+ JavaScript features
  • HTML5 Canvas API

๐Ÿ› ๏ธ Development

Local Development

# Clone the repository
git clone https://github.com/your-username/liquid-glass-js.git
cd liquid-glass-js

# Open in browser (requires local server for WebGL)
# For example, using serve
npx serve .

Building

No build step required! The library uses vanilla JavaScript and can be used directly.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style
  • Add comments for complex WebGL operations
  • Test across different browsers
  • Update documentation for new features

๐Ÿ“– Examples

const navContainer = new Container({
  type: 'rounded',
  borderRadius: 20,
  tintOpacity: 0.1
})

;['Home', 'About', 'Contact'].forEach(text => {
  const navButton = new Button({
    text: text,
    size: 16,
    type: 'pill',
    onClick: text => navigate(text)
  })
  navContainer.addChild(navButton)
})

Control Panel

const controlPanel = new Container({
  type: 'rounded',
  borderRadius: 12,
  tintOpacity: 0.6
})

const playButton = new Button({
  text: 'โ–ถ',
  size: 24,
  type: 'circle',
  onClick: () => player.play()
})

controlPanel.addChild(playButton)

๐Ÿ”ฎ Roadmap

  • Bundle for NPM
  • TypeScript rewrite
  • React/Vue component wrappers
  • Animation system
  • Accessibility improvements
  • Performance optimizations
  • Mobile touch optimizations

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by Apple's Liquid Glass design language
  • WebGL techniques from various computer graphics resources
  • html2canvas library for page capture functionality

Built with โค๏ธ for the future of web interfaces

Demo โ€ข Issues โ€ข Discussions

Significant stargazers

Daniel Strobusch

19 followers ยท starred Sep 2025

Languages

JavaScript

72.5%

HTML

19.1%

CSS

8.4%