CSS Portal

CSS mask-image Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The mask-image property specifies an image (or set of images) that is used as a mask to control the visibility of an element’s painted content. Conceptually the mask defines, on a per-pixel basis, how much of the element’s pixels are shown: areas of the mask that are “opaque” reveal the element and areas that are “transparent” hide it. Because it is a painting operation, using mask-image does not change the element’s layout boxes or DOM geometry — it only affects the final rendered pixels that the user sees.

In practice mask-image is often used where you want soft or complex edges, feathered fades, or non-rectangular visibility that cannot be achieved with simple clipping. Compared to geometric clipping with clip-path, which slices the element into a defined shape, mask-image operates at pixel precision so you can create smooth transitions, drop-off gradients, and partially transparent regions. Likewise, when you combine a mask with a background visual (for example a background picture), the mask modulates the appearance of that background as it modulates the element’s entire painting, so it is complementary to things applied by background-image.

mask-image is controlled and refined by the other mask-related properties that determine how the mask content is scaled, positioned and composed. For example, mask-size and mask-repeat change how the mask image is fitted and tiled relative to the element, while mask-mode affects whether the mask uses alpha channels or luminance to compute coverage. There is also a shorthand that bundles multiple mask settings together; using these properties in combination lets you achieve a wide range of visual masking effects without changing the document structure.

When applying masks keep performance and semantics in mind: masks can force extra offscreen rendering and rasterization steps, especially when they are large, use complex images, or change frequently (animated masks are particularly costly). Masks affect the visual outcome and what users perceive, which can influence accessibility — for instance, important content hidden by a mask might still be reachable to assistive technologies even though it is visually obscured, so be deliberate about using masking for purely decorative effects. Finally, masks interact with compositing and painting order, so be mindful of how they combine with other effects such as filters, shadows, and opacity when crafting your final appearance.

Definition

Initial value
none
Applies to
all elements; In SVG, it applies to container elements excluding the <defs> element and all graphics elements
Inherited
no
Computed value
as specified, but with <url> values made absolute
Animatable
yes
JavaScript syntax
object.style.maskImage

Syntax

mask-image: <mask-layer>;
mask-image: <mask-layer>, <mask-layer>, ...;

Values

  • noneThe default value. No mask is applied.
  • <image>A path to an image file (PNG, SVG, etc.) or a CSS gradient.
  • <mask-reference>A reference to an SVG element or a child() function.

Example

<div class='wrap'>
<div class='card'>
<div class='photo' aria-hidden='true'></div>
<div class='content'>
<h1>Masked Photo</h1>
<p>This example uses mask-image to fade the bottom of the image.</p>
<button>Learn more</button>
</div>
</div>
</div>
/* Layout */
body {
    margin: 0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(180deg, #eef2ff 0%, #ffffff 100%);
}

.wrap {
    padding: 24px;
}

.card {
    width: 380px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(16,24,40,0.12);
    background: #fff;
}

.photo {
    height: 220px;
    background-image: url('https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?auto=format&fit=crop&w=1200&q=80');
    background-size: cover;
    background-position: center;

    /* mask-image creates a fade at the bottom so the photo blends into the card */
    -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 60%, rgba(0,0,0,0) 100%);
    mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 60%, rgba(0,0,0,0) 100%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

.content {
    padding: 18px 20px 24px;
}

.content h1 {
    margin: 0 0 8px 0;
    font-size: 20px;
}

.content p {
    margin: 0 0 16px 0;
    color: #404040;
    font-size: 14px;
}

button {
    background: linear-gradient(90deg, #7c3aed, #06b6d4);
    color: white;
    border: none;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
}

button:active { transform: translateY(1px); }

Browser Support

The following information will show you the current browser support for the CSS mask-image property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!