Glassmorphism & Neumorphism: Premium UI Styling Techniques
Master modern UI styling with CSS. Learn how to build glassmorphism (frosted glass) and neumorphism (soft UI) effects using backdrop-filters, box-shadows, and gradients.
Introduction
Modern web design has evolved past simple flat surfaces. Websites like Apple, Windows 11, and Stripe use visual depth to guide users' attention. Two design trends dominate this aesthetic space:
- Glassmorphism (Frosted Glass): An effect that simulates a translucent, semi-transparent pane floating over a vibrant, colorful background.
- Neumorphism (Soft UI): An effect that simulates extruded physical surfaces using dual-colored soft inner and outer shadows, making elements look like they are molded out of the background.
Understanding how to construct these premium interfaces using native CSS properties like backdrop-filter, box-shadow, and linear-gradient is a key skill for frontend engineers preparing for UI development rounds.
What You Will Learn
- How to build a frosted glass container using
backdrop-filter: blur(). - Managing alpha opacity and borders to prevent muddy-looking glass interfaces.
- The mathematical rules behind dual-shadow neumorphism.
- The difference between convex, concave, flat, and inset neumorphic components.
- Performance considerations for complex visual filters.
Prerequisites
Detailed Explanation: Glassmorphism
Glassmorphism relies on a hierarchy of layers: a colorful backdrop, a semi-transparent card, a blur filter, and a subtle border highlight.
The CSS Formula for Perfect Glassmorphism
To make glass look realistic, you must combine four properties:
- Semi-transparent Background: Use
rgba()orhsla()to let background colors leak through. Keep opacity low (between0.1and0.3). - Backdrop Filter: Apply
backdrop-filter: blur(10px). This blurs the content behind the element, creating the frosted effect. - Card Border: Add a thin, semi-transparent white border. This mimics the edge reflections of real glass.
- Subtle Drop Shadow: Add a dark, soft shadow to elevate the card off the background.
.glass-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}
Detailed Explanation: Neumorphism
Neumorphism (Soft UI) is an interface style that uses highlight and shadow pairs to mimic physical form. Unlike standard cards that float on top of a page, neumorphic components appear to rise from or sink into the page itself.
The Shadow Math rule
For Neumorphism to work, the card color MUST match the page background color exactly. You then apply two shadows in opposite directions:
- Light Source Shadow (Top-Left): A light shadow (white) representing reflection.
- Opposite Shadow (Bottom-Right): A dark shadow (gray/black) representing obstruction.
.neumorphic-button {
background: #e0e0e0;
/* Shadow offset X, Y, blur radius, color */
box-shadow: 10px 10px 20px #bebebe,
-10px -10px 20px #ffffff;
}
Visual Learning Diagram (Mermaid)
graph TD
subgraph Glassmorphism Stack
Layer1[1. Vibrant Background <br> Gradients / Images] --> Layer2[2. Backdrop Filter Blur <br> blurs the background]
Layer2 --> Layer3[3. Semi-transparent Color <br> rgba 255,255,255,0.1]
Layer3 --> Layer4[4. Highlight Border <br> rgba 255,255,255,0.2]
end
Code Examples
Example 1: Frosted Glass Login Form Card
Let's build a premium glass container meant to sit over a colorful gradient background:
/* Container holding the background gradient */
.hero-wrapper {
min-height: 500px;
background: radial-gradient(circle at top left, #3b82f6, #06b6d4, #0f172a);
display: flex;
justify-content: center;
align-items: center;
padding: 40px;
}
/* Glassmorphic card styling */
.glass-login-box {
width: 100%;
max-width: 400px;
padding: 40px;
border-radius: 24px;
/* Frosted glass parameters */
background: rgba(255, 255, 255, 0.08);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px); /* Safari support */
/* Glass border and shadow elevation */
border: 1px solid rgba(255, 255, 255, 0.12);
box-shadow: 0 16px 32px rgba(0, 0, 0, 0.25);
}
.glass-input {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
color: white;
padding: 12px 16px;
border-radius: 8px;
}
Example 2: Neumorphic Flat and Pressable Cards
Here is how to create a neumorphic element that flips from an "extruded" (raised) shadow structure to a "pressed" (inset) structure when clicked:
.neumorphic-card {
width: 200px;
height: 200px;
border-radius: 30px;
background: #e0e0e0;
transition: all 0.2s ease-in-out;
cursor: pointer;
border: none;
/* Dual shadows for raised look */
box-shadow: 9px 9px 16px #bebebe,
-9px -9px 16px #ffffff;
}
.neumorphic-card:active {
/* Inset shadows make the button look pressed/hollowed */
box-shadow: inset 9px 9px 16px #bebebe,
inset -9px -9px 16px #ffffff;
}
Best Practices & Performance Optimization
Glassmorphism
- Contrast Ratios: Because the background of a glass container is semi-transparent, ensure your text colors maintain readability over the background. Use thick font weights or high-contrast foreground values.
- Performance Alert: Using
backdrop-filter: blur()forces the browser GPU to repaint layers constantly during scroll actions. Avoid using glassmorphism on dozens of elements simultaneously; restrict it to sticky header bars, overlays, and main floating modals.
Neumorphism
- Accessibility Warning: Because neumorphism relies on low-contrast shadows (
#bebebeon#e0e0e0), boundaries can be difficult for visually impaired users to recognize. Always supplement neumorphic elements with clear icons, high-contrast typography, or explicit focus rings (outline).
FAQs
Q: Why isn't my backdrop-filter blur working?
A: Ensure that the element has a semi-transparent background color (e.g. rgba(255, 255, 255, 0.2)). If the background is fully opaque (#fff), the blurred background will be hidden behind it.
Q: Can I use dark glassmorphism?
A: Absolutely! Instead of a white transparent fill, use a black transparent fill: rgba(15, 23, 42, 0.6). This is highly popular for dark mode dashboards.
Summary
Glassmorphism blends elements into background designs using translucent backdrops, blur parameters, and crisp light borders. Neumorphism models elements directly out of their background layout through dual light and dark shadow pairs, shifting into inset styles when interacting.
Related Articles
Next Tutorial
Let's move on to Module 4: Text & Typography to control styles, fonts, weights, and rendering structures of our content. Let's check: CSS Fonts and Families.