W3cubDocs

/SVG

mask

Baseline 2023
Newly available

Since ⁨December 2023⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The mask attribute is a presentation attribute mainly used to bind a given <mask> element with the element the attribute belongs to.

Note: As a presentation attribute, mask also has a CSS property counterpart: mask. When both are specified, the CSS property takes priority.

You can use this attribute with the following SVG elements:

Example

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <mask id="myMask" maskContentUnits="objectBoundingBox">
    <rect fill="white" x="0" y="0" width="100%" height="100%" />
    <polygon
      fill="black"
      points="0.5,0.2 0.68,0.74 0.21,0.41 0.79,0.41 0.32,0.74" />
  </mask>

  <!--
  Punch a hole in a shape of a star inside the red circle,
  revealing the yellow circle underneath
  -->
  <circle cx="50" cy="50" r="20" fill="yellow" />
  <circle cx="50" cy="50" r="45" fill="red" mask="url(#myMask)" />
</svg>

Since SVG2, the mask attribute is defined as a CSS property and is a shorthand for many other properties: mask-image, mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-size, and mask-composite.

Usage notes

Value See the CSS property mask
Default value none
Animatable Yes

Specifications

Browser compatibility

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 120
1The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
1–120While the property is recognized, values applied to it don't have any effect.
120
79The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
79–120While the property is recognized, values applied to it don't have any effect.
12–79
53
2–53Only supports mask: url(file.svg#mask_id) or mask: url(#mask_id), where the URL is a reference to an SVG <mask> element.
106
15The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
15–106While the property is recognized, values applied to it don't have any effect.
15.4
3.1The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
3.1–15.4While the property is recognized, values applied to it don't have any effect.
120
18The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
18–120While the property is recognized, values applied to it don't have any effect.
53
4–53Only supports mask: url(file.svg#mask_id) or mask: url(#mask_id), where the URL is a reference to an SVG <mask> element.
80
14The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
14–80While the property is recognized, values applied to it don't have any effect.
15.4
2The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
2–15.4While the property is recognized, values applied to it don't have any effect.
25.0
1.0The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
1.0–25.0While the property is recognized, values applied to it don't have any effect.
120
3The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
3–120While the property is recognized, values applied to it don't have any effect.
15.4
2The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard -webkit-mask-attachment property.
2–15.4While the property is recognized, values applied to it don't have any effect.

See also

© 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/Attribute/mask