--- title: slug: Web/SVG/Element/mask tags: - Element - SVG - SVG Container translation_of: Web/SVG/Element/mask ---
{{SVGRef}}

The <mask> element defines an alpha mask for compositing the current object into the background. A mask is used/referenced using the {{SVGAttr("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>

{{EmbedLiveSample('Example', 100, 100)}}

属性

{{SVGAttr("height")}}
This attribute defines the height of the masking area.
Value type: <length> ; Default value: 120%; Animatable: yes
{{SVGAttr("maskContentUnits")}}
This attribute defines the coordinate system for the contents of the <mask>.
Value typeuserSpaceOnUse|objectBoundingBox ; Default value: userSpaceOnUse; Animatable: yes
{{SVGAttr("maskUnits")}}
This attribute defines defines the coordinate system for attributes {{SVGAttr("x")}}, {{SVGAttr("y")}}, {{SVGAttr("width")}} and {{SVGAttr("height")}} on the <mask>.
Value typeuserSpaceOnUse|objectBoundingBox ; Default value: objectBoundingBox; Animatable: yes
{{SVGAttr("x")}}
This attribute defines the x-axis coordinate of the top-left corner of the masking area.
Value type: <coordinate> ; Default value: -10%; Animatable: yes
{{SVGAttr("y")}}
This attribute defines the y-axis coordinate of the top-left corner of the masking area.
Value type: <coordinate> ; Default value: -10%; Animatable: yes
{{SVGAttr("width")}}
This attribute defines the width of the masking area.
Value type: <length> ; Default value: 120%; Animatable: yes

Global attributes

Core Attributes
Most notably: {{SVGAttr('id')}}
Styling Attributes
{{SVGAttr('class')}}, {{SVGAttr('style')}}
Conditional Processing Attributes
Most notably: {{SVGAttr('requiredExtensions')}}, {{SVGAttr('systemLanguage')}}
Presentation Attributes
Most notably: {{SVGAttr('clip-path')}}, {{SVGAttr('clip-rule')}}, {{SVGAttr('color')}}, {{SVGAttr('display')}}, {{SVGAttr('fill')}}, {{SVGAttr('fill-opacity')}}, {{SVGAttr('fill-rule')}}, {{SVGAttr('filter')}}, {{SVGAttr('mask')}}, {{SVGAttr('opacity')}}, {{SVGAttr('shape-rendering')}}, {{SVGAttr('stroke')}}, {{SVGAttr('stroke-dasharray')}}, {{SVGAttr('stroke-dashoffset')}}, {{SVGAttr('stroke-linecap')}}, {{SVGAttr('stroke-linejoin')}}, {{SVGAttr('stroke-miterlimit')}}, {{SVGAttr('stroke-opacity')}}, {{SVGAttr('stroke-width')}}, {{SVGAttr("transform")}}, {{SVGAttr('vector-effect')}}, {{SVGAttr('visibility')}}

Usage notes

{{svginfo}}

仕様

仕様書 ステータス コメント
{{SpecName('CSS Masks', '#MaskElement', '<mask>')}} {{Spec2('CSS Masks')}}  
{{SpecName('SVG1.1', 'masking.html#Masking', '<mask>')}} {{Spec2('SVG1.1')}} 初期定義

ブラウザの互換性

{{Compat("svg.elements.mask")}}

あわせて参照