← Back to Vibe Coding

Glassmorphism UI Effect

June 28, 25

Glassmorphism

This is a frosted glass effect card. The effect creates a translucent surface that mimics the appearance of frosted glass.

Creating Glassmorphism UI Elements

Glassmorphism is a modern UI design trend that creates a frosted glass effect for interface elements. It's characterized by background blur, transparency, and subtle borders.

Key CSS Properties

Implementation Code

Here's the CSS that powers the glassmorphism effect:

/* Background with gradient for better effect visibility */
.glass-container {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(45deg, #ff9a9e, #fad0c4, #fad0c4, #a1c4fd);
  background-size: 400% 400%;
  animation: gradient 15s ease infinite;
  padding: 20px;
}

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* Glass card */
.glass-card {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 40px;
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
  width: 300px;
  text-align: center;
}

/* Glass button */
.glass-button {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 10px 20px;
  color: white;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.glass-button:hover {
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 16px 0 rgba(31, 38, 135, 0.2);
}

Browser Compatibility

The key property for glassmorphism is backdrop-filter, which has the following browser support:

Design Tips

  1. Use colorful backgrounds: The glass effect is most visible against colorful, gradient backgrounds.
  2. Light border: Add a subtle light border to enhance the glass effect.
  3. Subtle shadows: Use soft shadows to create depth without breaking the glass illusion.
  4. Text contrast: Ensure text has enough contrast against the transparent background.
  5. Don't overuse: Glassmorphism works best when used selectively for key UI elements.