This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The <mask> SVG element defines a mask for compositing the current object into the background. A mask is used/referenced using the mask property and CSS mask-image property.
| Categories | Container element |
|---|---|
| Permitted content | Any number of the following elements, in any order: Animation elements Descriptive elements Shape elements Structural elements Gradient elements <a>, <clipPath>, <filter>, <foreignObject>, <image>, <marker>, <mask>, <pattern>, <script>, <style>, <switch>, <text>, <view>
|
heightThis attribute defines the height of the masking area. Value type: <length>; Default value: 120%; Animatable: yes
mask-typeThis attribute defines the mask mode for the contents for the contents of the <mask>. Value type: alpha | luminance; Default value: luminance; Animatable: yes
maskContentUnitsThis attribute defines the coordinate system for the contents of the <mask>. Value type: userSpaceOnUse | objectBoundingBox; Default value: userSpaceOnUse; Animatable: yes
maskUnitsThis attribute defines the coordinate system for attributes x, y, width and height on the <mask>. Value type: userSpaceOnUse | objectBoundingBox; Default value: objectBoundingBox; Animatable: yes
xThis attribute defines the x-axis coordinate of the top-left corner of the masking area. Value type: <coordinate>; Default value: -10%; Animatable: yes
yThis attribute defines the y-axis coordinate of the top-left corner of the masking area. Value type: <coordinate>; Default value: -10%; Animatable: yes
widthThis attribute defines the width of the masking area. Value type: <length>; Default value: 120%; Animatable: yes
This element implements the SVGMaskElement interface.
<svg viewBox="-10 -10 120 120">
<rect x="-10" y="-10" width="120" height="120" fill="blue" />
<mask id="myMask" mask-type="luminance">
<!-- Everything under a white pixel will be visible -->
<rect x="0" y="0" width="100" height="100" fill="white" />
<!-- Everything under a black pixel will be invisible -->
<path
d="M10,35 A20,20,0,0,1,50,35 A20,20,0,0,1,90,35 Q90,65,50,95 Q10,65,10,35 Z"
fill="black" />
</mask>
<polygon points="-10,110 110,110 110,-10" fill="orange" />
<!-- with this mask applied, we "punch" a heart shape hole into the circle -->
<circle cx="50" cy="50" r="50" fill="purple" mask="url(#myMask)" />
</svg>
| Specification |
|---|
| CSS Masking Module Level 1> # MaskElement> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
mask |
1 | 12 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
height |
1 | 12 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
maskContentUnits |
1 | 79 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
maskUnits |
1 | 79 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
systemLanguage |
1 | 12 | 12 | 15 | 3 | 18 | 14 | 14 | 2 | 1.0 | 4.4 | 2 |
width |
1 | 12 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
x |
1 | 12 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
y |
1 | 12 | 3 | 15 | 3 | 18 | 4 | 14 | 2 | 1.0 | 4.4 | 2 |
mask-type property<clipPath>
mask, mask-image, mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-composite, mask-size
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/mask