Glassmorphism with CSS Gradients
The glassmorphism effect combines four CSS properties to create a frosted-glass appearance that lets background content show through a translucent, blurred surface. A semi-transparent gradient background tints the glass. backdrop-filter: blur() frosted the content behind the element.1 A translucent border adds the glass-edge highlight. A subtle box-shadow grounds the panel.
The gradient must use colors with alpha below 1: solid opaque stops block the blur effect entirely. Consequently, rgba() or oklch() colors with alpha between 0.05 and 0.4 keep the glass translucency while adding a color tint to the panel.2 Building on this, Safari requires -webkit-backdrop-filter alongside the standard property for full support.3 Performance is a known consideration: backdrop-filter triggers compositing layer promotion, which consumes GPU memory. For mobile UIs with many glassmorphism panels, limiting the number of active blur layers is important.
The four-layer composition
A glassmorphism panel assembles four visual layers.4 First: a semi-transparent gradient background that tints the glass and establishes color. Second: backdrop-filter: blur(12px) that frosted the content behind the element. Third: a 1px solid border using an rgba() or oklch() color at 0.15 to 0.3 alpha, which provides the edge highlight without outlining the panel heavily. Fourth: a box-shadow using a low-alpha dark color for grounding. Each layer contributes a distinct visual property, and removing any one of them diminishes the frosted-glass illusion. Understanding how these four layers interact helps you debug rendering issues: if the blur looks wrong, check the alpha values; if the panel looks flat, verify the border and shadow are both present.
The directional tint created by a diagonal gradient also helps establish a consistent light source across multiple glassmorphism panels on the same page, which reinforces the three-dimensional layering effect that makes the frosted-glass aesthetic feel cohesive rather than arbitrary. For hero sections that overlay rich imagery, a 135deg gradient with a subtle white-to-transparent stop pattern mimics the way real glass catches ambient light from above.
Gradient alpha requirements
The gradient alpha must stay below 1 throughout for the blur to remain visible. A stop at rgba(255, 255, 255, 0.1) for the top (simulating a top-light glass reflection) and rgba(255, 255, 255, 0.03) for the bottom produces a subtle top-lit effect. Yet using a single flat rgba() background-color without a gradient is also valid for glassmorphism; the gradient adds a directional tint quality that flat colors do not have.
Building on this, diagonal gradients (135deg) often read more naturally as a glass surface than vertical or horizontal ones because the angled light catch mimics how real glass reflects ambient light from a window or overhead source, and the directional tint helps establish a consistent light source across multiple glassmorphism panels on the same page.
Why the gradient must use alpha below 1
backdrop-filter applies to the content behind the element. For the blur to remain visible, the element's background must allow some content to show through. A fully opaque background completely blocks the blurred content, making the blur invisible regardless of the backdrop-filter value. Alpha values between 0.05 and 0.4 balance translucency with color tint, which is the range where you can set a glass tint that still lets the blur through instead of flattening it into a solid panel.
Alpha values between 0.05 and 0.4 balance translucency with color tint. At 0.05, the tint is nearly invisible and the blurred background dominates. At 0.4, the tint becomes a strong color overlay and the blur is less visible through it. Yet neither extreme serves the glassmorphism aesthetic well: too little alpha removes the glass color character; too much alpha blocks the blur that defines the style.
Furthermore, OLED displays render low-alpha dark stops as genuinely transparent rather than a very dark opaque color, which affects how the blur appears on high-contrast backgrounds. On OLED panels, a gradient stop at oklch(0 0 0 / 0.05) is genuinely transparent rather than a near-black tint, which means the blur effect is more visible through the dark regions of the gradient than it would be on an LCD panel with the same CSS values. This OLED transparency behavior means you can use darker gradient stops on OLED-targeted designs without sacrificing the blur visibility, allowing for richer dark-mode glassmorphism panels that still let background content show through.
Browser support and compositing layer performance
backdrop-filter has full support in Chrome, Edge, Firefox, and Safari. Safari requires the -webkit-backdrop-filter property in addition to the standard backdrop-filter for complete cross-browser support. Both properties accept the same value: blur(12px). On desktop browsers with dedicated GPUs, the compositing cost is minimal for a few panels, but on mobile browsers and low-end hardware, multiple overlapping backdrop-filter elements can reduce frame rate noticeably during scroll and animation.
GPU compositing cost
backdrop-filter promotes the element to its own GPU compositing layer.5 Each layer consumes GPU memory and requires the browser to composite the blurred background separately from the main page layer. On desktop browsers with dedicated GPUs, this cost is minimal for a few panels. Yet on mobile browsers and low-end hardware, multiple overlapping backdrop-filter elements can reduce frame rate noticeably during scroll and animation.
Consequently, glassmorphism panels should be positioned away from frequently scrolling content, and their count per page should be limited to avoid stacking compositing costs. Building on this, testing glassmorphism performance on mid-range Android hardware (Samsung Galaxy A series) reveals real-world compositing limits that desktop-only testing misses. For pages that need many glassmorphism panels, adding @media (prefers-reduced-motion: reduce) to disable blur on low-end devices provides a graceful fallback that preserves the visual hierarchy without the GPU cost. A practical limit for most mobile layouts is three to four simultaneous backdrop-filter elements visible in the viewport at once; beyond that, consider replacing some panels with a simpler translucent background color that achieves a similar visual weight without the compositing overhead.
Inner shadows and border highlights for the glass edge effect
The glass edge highlight comes from the border, not from a separate visual element. A 1px solid rgba(255,255,255,0.2) border on a dark background produces the edge highlight at zero additional DOM cost. On a lighter background, reducing the alpha to 0.08 to 0.12 maintains the edge definition without making the border appear as a heavy outline that draws attention away from the panel content.
Multiple box-shadow values on a single element compose the glassmorphism shadow system without extra markup. The outer shadow grounds the panel on the page: box-shadow: 0 8px 32px rgba(0,0,0,0.12). An inner shadow adds the top-edge light catch: box-shadow: inset 0 1px 0 rgba(255,255,255,0.15). Combining both with comma separation on the box-shadow property produces the full layered effect in one declaration.
Color-matching the border highlight to the gradient
A gradient background running from a lighter stop at the top to a darker stop at the bottom benefits from matching the border highlight alpha to the top stop's lightness. At oklch(1 0 0 / 0.15) for the top gradient stop, a border at rgba(255,255,255,0.15) continues the same light intensity at the element edge. This consistency across the gradient direction makes the glass surface read as three-dimensional rather than flat with a decorative border applied on top.
When to use this
Use glassmorphism for modal dialogs, floating panels, navigation bars, and card components that overlay rich visual content. Avoid it for high-density UI like data tables, forms, or any layout with many overlapping panels that would stack multiple compositing layers.
Examples
Frosted-glass card overlaid on a gradient hero image
Set background: linear-gradient(135deg, rgba(255,255,255,0.12), rgba(255,255,255,0.04)) on the card. Add backdrop-filter: blur(12px) and -webkit-backdrop-filter: blur(12px). Use border: 1px solid rgba(255,255,255,0.18) and box-shadow: 0 4px 24px rgba(0,0,0,0.12) to complete the four-layer composition.
Dark glassmorphism panel on a dark background
For dark backgrounds, use rgba(0,0,0,0.3) as the gradient color instead of white. A dark-tinted glass panel on a dark background creates a differentiated surface without the white-tint approach used for light surfaces. Reduce blur to 8px as heavy blur on dark backgrounds can appear muddy.
Navigation bar with glassmorphism and sticky positioning
Apply position: sticky; top: 0 with the four-layer glassmorphism composition to a nav element. The sticky navigation overlays page content as the user scrolls, with the blurred background making the scroll position visible through the nav. Test scroll performance on mobile; sticky glassmorphism navs are a common source of compositing jank.
- 1.
MDN Web Docs, "backdrop-filter CSS property," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/backdrop-filter
- 2.
MDN Web Docs, "Stacking context," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Positioned_layout/Stacking_context
- 3.
Adam Argyle and Joe Medley, "Create OS-style backgrounds with backdrop-filter," web.dev, accessed June 2026. https://web.dev/articles/backdrop-filter
- 4.
Paul Lewis, "Stick to Compositor-Only Properties and Manage Layer Count," web.dev, accessed June 2026. https://web.dev/articles/stick-to-compositor-only-properties-and-manage-layer-count
- 5.
Brent Fulgham, "Introducing Backdrop Filters," webkit.org, August 2015. https://webkit.org/blog/3632/introducing-backdrop-filters/