CSS mask-image: Alpha Gradients, Vector Shapes & Cutout Masks
CSS mask-image applies an alpha transparency mask to any element. Unlike clip-path (which only produces sharp, binary polygon cutouts), mask-image supports soft, 8-bit alpha transparency gradients (e.g. mask-image: linear-gradient(to bottom, black 60%, transparent 100%)) and complex vector SVGs with translucent antialiased edges. Pair with -webkit-mask-image for 100% cross-browser rendering.
Step 1: mask-image vs clip-path: When to Use Which
Use clip-path when you need geometric cuts with hard, crisp vector edges (like triangles or polygons). Use mask-image when you require soft gradient fades, feathered vignette spotlights, or raster PNG cutouts with variable alpha transparency.
/* clip-path: Hard geometric polygon */
.hard-cut {
clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
}
/* mask-image: Smooth 8-bit alpha gradient fade */
.soft-fade {
-webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
}
Step 2: Radial Vignettes & Spotlight Reveals
Create elegant photographic spotlights using radial gradient masks. Setting the center to black (fully visible) and feathering to transparent produces a natural focus vignette.
.spotlight-portrait {
-webkit-mask-image: radial-gradient(circle at center, black 40%, transparent 80%);
mask-image: radial-gradient(circle at center, black 40%, transparent 80%);
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}
Step 3: Vector SVG Masks: Complex Cutout Brand Shapes
Reference external or inline vector SVG graphics as the mask source. The shape of the vector graphic cuts through the HTML element, supporting intricate brand marks and organic blob contours.
.brand-masked-hero {
-webkit-mask-image: url('brand-monogram.svg');
mask-image: url('brand-monogram.svg');
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-position: center;
mask-position: center;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}
Step 4: Compositing Multiple Masks with mask-composite
Combine multiple mask layers using mask-composite: add | subtract | intersect | exclude. This allows you to punch cutouts out of linear fades directly in CSS without opening Photoshop.
.complex-mask {
mask-image:
linear-gradient(to bottom, black, transparent),
radial-gradient(circle at top right, black 30%, transparent 70%);
mask-composite: intersect; /* Only visible where both masks overlap */
}
Next-Level Addons: Elevating Your Implementation
Take this technique further by combining it with complementary design token studios and animation tools:
A trick I use in almost every project: don't fight specificity battles with !important. Leverage modern CSS cascade layers (@layer) and CSS variables as design tokens—it makes dark/light theme switching and responsive tuning effortless.
Frequently Asked Questions
Practical answers to common implementation questions, browser quirks, and performance tips.
Why do I need to include -webkit-mask-image alongside mask-image?
While standard `mask-image` is widely supported, Safari, Chrome, and Edge still maintain legacy WebKit rendering pipeline paths for mask sizing and composite operations. Declaring both ensures 100% visual consistency.
In CSS mask-image, does black mean visible and white mean transparent?
By default (`mask-mode: alpha`), opacity is dictated by the alpha channel of the mask image (opaque = visible, transparent = hidden). If you switch to luminance mode (`mask-mode: luminance`), white is 100% visible and black is completely transparent.
Can mask-image be animated with CSS transitions?
Yes! You can smoothly animate `mask-position` and `mask-size` (such as expanding a radial spotlight on hover). Animating gradient color stops is also supported in modern Chromium and Safari.
Does mask-image hide elements from accessibility screen readers?
No. Visual masking only affects pixel transparency on screen. Screen readers continue to read text inside a masked container unless it is explicitly marked with `aria-hidden="true"`.
Can I apply mask-image to an HTML5
Yes! `mask-image` works identically on `