CSS mask Property
- Previous Page marker-start
- Next Page mask-clip
Definition and Usage
mask
The property is used to hide elements by masking or clipping images (partially or entirely).
mask
The property is a shorthand for the following properties:
Instance
Example 1
Create a mask layer for images:
.mask1 { mask: url(w3logo.png) no-repeat 50% 50%; }
Example 2
Create different mask layers for images using linear gradients and radial gradients:
.mask1 { mask: linear-gradient(black, transparent); } .mask2 { mask: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%); } .mask3 { mask: radial-gradient(ellipse, black 50%, rgba(0, 0, 0, 0.5) 50%); }
Example 3
Use the SVG <mask> element to create a mask layer for images:
<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>
Example 4
Use the SVG <mask> element to create a mask layer for images:
<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>
CSS Syntax
mask-image: mask-image mask-mode mask-repeat mask-position mask-clip mask-origin mask-size mask-composite|initial|inherit;
Property Value
Value | Description |
---|---|
mask-image | Specifies the image used as the element mask layer. The default value is none. |
mask-mode |
Specifies whether the mask layer image should be considered as a luminance mask or an alpha mask. The default value is match-source. |
mask-repeat |
Sets whether and how the mask image is repeated. The default value is repeat. |
mask-position |
Sets the starting position of the mask image (relative to the mask position area). The default value is 0% 0%. |
mask-clip |
Specifies the area affected by the mask image. The default value is border-box. |
mask-origin |
Specifies the starting position of the mask layer image (the mask position area). The default value is border-box. |
mask-size |
Specifies the size of the mask layer image. The default value is auto. |
mask-composite |
Specifies the composite operation used between the current mask layer and the layer below it. The default value is add. |
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 match-source repeat 0% 0% border-box border-box auto add |
---|---|
Inheritance: | No |
Animation creation: | Not supported. See:Animation-related properties. |
Version: | CSS Masking Module Level 1 |
JavaScript Syntax: | object.style.mask="url(star.svg)" |
Browser Support
The numbers in the table represent the first browser version to fully support this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
120 | 120 | 53 | 15.4 | 106 |
Related Pages
Tutorial:CSS Mask
Reference:CSS mask Property
Reference:CSS mask-clip Property
Reference:CSS mask-composite Property
Reference:CSS mask-image 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
- Previous Page marker-start
- Next Page mask-clip