The <mask> element defines an alpha mask for compositing the current object into the background. A mask is used/referenced using the mask property.
<svg viewBox="-10 -10 120 120">
<mask id="myMask">
<!-- 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" mask="url(#myMask)" />
</svg> height120%; Animatable: yes
maskContentUnits<mask>.userSpaceOnUse|objectBoundingBox ; Default value: userSpaceOnUse; Animatable: yes
maskUnitsx, y, width and height on the <mask>.userSpaceOnUse|objectBoundingBox ; Default value: objectBoundingBox; Animatable: yes
x-10%; Animatable: yes
y-10%; Animatable: yes
width120%; Animatable: yes
idclass, stylerequiredExtensions, systemLanguageclip-path, clip-rule, color, display, fill, fill-opacity, fill-rule, filter, mask, opacity, shape-rendering, stroke, stroke-dasharray, stroke-dashoffset, stroke-linecap, stroke-linejoin, stroke-miterlimit, stroke-opacity, stroke-width, transform, vector-effect, visibility| 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>, <altGlyphDef>, <clipPath>, <color-profile>, <cursor>, <filter>, <font>, <font-face>, <foreignObject>, <image>, <marker>, <mask>, <pattern>, <script>, <style>, <switch>, <text>, <view>
|
| Specification | Status | Comment |
|---|---|---|
| CSS Masking Module Level 1 The definition of '<mask>' in that specification. | Candidate Recommendation | |
| Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of '<mask>' in that specification. | Recommendation | Initial definition |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Yes | Yes | Yes | Yes | Yes |
maskUnits |
? | ? | ? | ? | ? | ? |
maskContentUnits |
? | ? | ? | ? | ? | ? |
x |
Yes | Yes | Yes | Yes | Yes | Yes |
y |
Yes | Yes | Yes | Yes | Yes | Yes |
height |
Yes | Yes | Yes | Yes | Yes | Yes |
width |
Yes | Yes | Yes | Yes | Yes | Yes |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | Yes | Yes | Yes | ? |
maskUnits |
? | ? | ? | ? | ? | ? | ? |
maskContentUnits |
? | ? | ? | ? | ? | ? | ? |
x |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
y |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
height |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
width |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
<clipPath>
mask, mask-image,mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-composite, mask-size, pointer-events
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/mask