このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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.

mask 属性は、主に指定された <mask> 要素とその属性が属する要素を結びつけるために使用されるプレゼンテーション属性です。

メモ: プレゼンテーション属性であるため、 mask には対応する CSS プロパティ mask があります。両方が指定された場合、 CSS プロパティが優先されます。

この属性は以下の SVG 要素で使用することができます。

html
<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>

  <!--
  赤丸の中に星形の穴を開け、
  丸の下の黄色を見せます。
  -->
  <circle cx="50" cy="50" r="20" fill="yellow" />
  <circle cx="50" cy="50" r="45" fill="red" mask="url(#myMask)" />
</svg>

SVG2 以降、mask 属性は CSS プロパティとして定義されており、多くの他のプロパティ (mask-image, mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-size, mask-composite) の一括指定となっています。

使用上のメモ

CSS プロパティ mask を参照
既定値 none
アニメーション

仕様書

Specification
CSS Masking Module Level 1
# the-mask

ブラウザーの互換性

関連情報

  • CSS の mask プロパティ