CSS mask-image Property


Example

Create a mask layer for an image:

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

More "Try it Yourself" examples below.


Definition and Usage

The mask-image property specifies an image to be used as a mask layer for an element.

Tip: Linear and radial gradients in CSS can also be used as the mask image.

Default value: none
Inherited: no
Animatable: no. Read about animatable
Version: CSS3
JavaScript syntax: object.style.maskImage="url(star.svg)"

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Numbers followed by -webkit- specify the first version that worked with a prefix.

Property
mask-image 4.0 -webkit- 79.0 -webkit- 53.0 4.0 -webkit- 15.0 -webkit-

CSS Syntax

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

Property Values

Value Description
none This is default
image An image to use as the mask layer
url An url reference to an image or an SVG <mask> element
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit


More Examples

Example

Create different mask layers for an image with 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

Use the SVG <mask> element to create a mask layer for an 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

Use the SVG <mask> element to create a mask layer for an 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 »

Related Pages

CSS reference: mask-mode property

CSS reference: mask-origin property

CSS reference: mask-position property

CSS reference: mask-repeat property

CSS reference: mask-size property

CSS tutorial: CSS Masking


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.