CSS mask-image property

Definition and Usage

mask-image The property is used to specify the image used as the element's mask.

Tip:CSS linear gradients and radial gradients can also be used as mask images.

Instance

Example 1

Create a mask layer for the image:

.mask1 {
  -webkit-mask-image: url(w3logo.png);
  mask-image: url(w3logo.png);
  mask-size: 70%;
  mask-repeat: no-repeat;
}

Try It Yourself

Example 2

Create different mask layers for images using linear and radial gradients:

.mask1 {
  -webkit-mask-image: linear-gradient(black, transparent);
  mask-image: linear-gradient(black, transparent);
}
.mask2 {
  -webkit-mask-image: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%);
  mask-image: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%);
}
.mask3 {
  -webkit-mask-image: radial-gradient(black 50%, rgba(0, 0, 0, 0.5) 50%);
  mask-image: radial-gradient(black 50%, rgba(0, 0, 0, 0.5));
}

Try It Yourself

Example 3

Use the SVG <mask> element to create a masking layer for the image:

<svg width="600" height="400">
  <mask id="svgmask1">
    <polygon fill="#ffffff" points="100,10 40,198 190,78 10,78 160,198"></polygon>
  </mask>
  <image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="img_5terre.jpg" mask="url(#svgmask1)"></image>
</svg>

Try It Yourself

Example 4

Use the SVG <mask> element to create another masking layer for the image:

<svg width="600" height="400">
  <mask id="svgmask1">
    <circle fill="#ffffff" cx="75" cy="75" r="75"></circle>
    <circle fill="#ffffff" cx="80" cy="260" r="75"></circle>
    <circle fill="#ffffff" cx="270" cy="160" r="75"></circle>
  </mask>
  <image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="img_5terre.jpg" mask="url(#svgmask1)"></image>
</svg>

Try It Yourself

CSS Syntax

mask-image: none|image|url()|initial|inherit;

Property Value

Value Description
none Default Value. No masking image is used.
image Used as the image for the masking layer.
url() URL reference for an image or SVG <mask> element.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical Details

Default Value: none
Inheritance: No
Animation Creation: Not supported. See:Animation-related properties.
Version: CSS Masking Module Level 1
JavaScript Syntax: object.style.maskImage="url(star.svg)"

Browser Support

The numbers in the table indicate the first browser version to fully support this property.

Numbers with the '-webkit-' prefix indicate the first version to support this prefix.

Chrome Edge Firefox Safari Opera
120 120 53 15.4 15 -webkit-

Related Pages

Tutorial:CSS Mask

Reference:CSS mask property

Reference:CSS mask-clip property

Reference:CSS mask-composite property

Reference:CSS mask-mode property

Reference:CSS mask-origin property

Reference:CSS mask-position property

Reference:CSS mask-repeat property

Reference:CSS mask-size property

Reference:CSS mask-type property