SnippetUI

Glassmorphism Modal

A beautiful glass-like modal dialog with a blurred background.

Tailwind CSSJavaScript

A modern modal window that allows the background to be seen through like frosted glass.

Preview

Glassmorphism

This is a beautiful glassmorphism modal popup using Tailwind CSS backdrop-blur utilities.

Use Cases & Features

  • Promotions and Alerts: Perfect for important messages that really grab the user’s attention or pop-ups that require action.
  • Modern Visuals: Blur the background (glassmorphism) to highlight the foreground content while preserving the background context.
  • Produces a sense of luxury: Gives a sense of depth and transparency, giving a more sophisticated impression than a simple solid color background.

Key points of design and UX (Design & UX)

  • Backdrop Blur: Uses Tailwind CSS’s backdrop-blur utility to beautifully blur the background elements.
  • Border and Transparency: By combining a translucent background color and border, such as bg-white/20 and border-white/30, a realistic glass texture is expressed.
  • Added animation: When the modal is displayed, a fade-in and slight scale-up animation is added to create a more natural appearance.

How to customize (Customization Guide)

  • Frost glass strength: You can adjust the blur strength by changing the backdrop-blur-md or backdrop-blur-xl class.
  • Changing the color theme: By changing the background overlay color (bg-black/20) or the base color of the modal itself, you can match it with the dark theme or brand color.

Implementation code (Implementation)

<!-- Container with background to demonstrate glass effect -->
<div class="relative w-full h-screen bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center">
<button id="open-modal" class="px-6 py-2 bg-white/20 hover:bg-white/30 backdrop-blur-md text-white font-medium rounded-lg border border-white/30 transition-all">Open Modal</button>

<div id="glass-modal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-300">
  <!-- Overlay -->
  <div class="absolute inset-0 bg-black/20 backdrop-blur-sm"></div>
  
  <!-- Modal Box -->
  <div class="relative bg-white/20 dark:bg-black/30 backdrop-blur-xl border border-white/30 dark:border-white/10 rounded-2xl p-8 max-w-sm w-full shadow-2xl transform scale-95 transition-transform duration-300">
    <h3 class="text-xl font-bold text-white mb-2">Glassmorphism</h3>
    <p class="text-white/80 mb-6 text-sm">This is a beautiful glassmorphism modal popup using Tailwind CSS backdrop-blur utilities.</p>
    <button id="close-modal" class="w-full py-2 bg-white/20 hover:bg-white/30 text-white rounded-lg transition-colors font-medium border border-white/20">Close</button>
  </div>
</div>
</div>
<script>
const modal = document.getElementById('glass-modal');
const inner = modal.querySelector('.transform');

document.getElementById('open-modal').addEventListener('click', () => {
  modal.classList.remove('opacity-0', 'pointer-events-none');
  inner.classList.remove('scale-95');
  inner.classList.add('scale-100');
});

document.getElementById('close-modal').addEventListener('click', () => {
  modal.classList.add('opacity-0', 'pointer-events-none');
  inner.classList.add('scale-95');
  inner.classList.remove('scale-100');
});
</script>