mask-type

  • Revision slug: Web/CSS/mask-type
  • Revision title: mask-type
  • Revision id: 450045
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }} {{SeeCompatTable}}

The CSS mask-type properties defines if a SVG {{SVGElement("mask")}} element is a luminance or an alpha mask.

  • {{ Xref_cssinitial() }} luminance
  • Applies to {{SVGElement("mask")}}
  • {{ Xref_cssinherited() }} no
  • Media {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }} {{cssuniqueorderdef}}
  • Animatable {{cssnotanimatabledef}}

Syntax

mask-type: luminance | alpha

Values

luminance
Is a keyword indicating that the associated {{SVGElement("mask")}} is a luminance mask, that is that its relative luminance values must be used when applying it.
alpha
Is a keyword indicating that the associated {{SVGElement("mask")}} is an alpha mask, that is that its alpha channel values must be used when applying it.

Examples

Let's apply the following rectangle as a mask:

<rect x="10" y="10" width="80" height="80" fill="red" fill-opacity="0.7" />
which leads to the following square: {{ EmbedLiveSample('mask', '100%', '100') }}

to this box:

{{ EmbedLiveSample('box', '100%', '100') }}

The result, if your browser supports the property, with different value of mask-type applied to the {{SVGElement("mask")}} element are these two different squares:

mask-type: alpha; mask-type: luminance;
{{ EmbedLiveSample('maskalpha', '100%', '100') }}
{{ EmbedLiveSample('maskluminance', '100%', '100') }}

Specifications

Specification Status Comment
{{ SpecName('CSS Masks', '#mask-type', 'mask') }} {{ Spec2('CSS Masks') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 24.0 {{CompatGeckoDesktop("20.0")}} {{ CompatNo() }} 15.0 {{ CompatNo() }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{CompatGeckoMobile("20.0")}} {{ CompatNo() }} 15.0 {{ CompatNo() }}

See also

  • Other mask-related properties: {{cssxref("mask")}}

Revision Source

<div>
  {{ CSSRef() }} {{SeeCompatTable}}</div>
<p>The CSS <code>mask-type</code> properties defines if a SVG {{SVGElement("mask")}} element is a <em>luminance</em> or an <em>alpha mask</em>.</p>
<ul class="cssprop">
  <li><dfn>{{ Xref_cssinitial() }}</dfn> <code>luminance</code></li>
  <li><dfn>Applies to</dfn> {{SVGElement("mask")}}</li>
  <li><dfn>{{ Xref_cssinherited() }}</dfn> no</li>
  <li><dfn>Media</dfn> {{ Xref_cssvisual() }}</li>
  <li><dfn>{{ Xref_csscomputed() }}</dfn> {{cssuniqueorderdef}}</li>
  <li><dfn>Animatable</dfn> {{cssnotanimatabledef}}</li>
</ul>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
mask-type: luminance | alpha</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <code>luminance</code></dt>
  <dd>
    Is a keyword indicating that the associated {{SVGElement("mask")}} is a luminance mask, that is that its <a href="http://en.wikipedia.org/wiki/Luminance_%28relative%29" title="http://en.wikipedia.org/wiki/Luminance_%28relative%29">relative luminance</a> values must be used when applying it.</dd>
  <dt>
    <code>alpha</code></dt>
  <dd>
    Is a keyword indicating that the associated {{SVGElement("mask")}} is an alpha mask, that is that its <a href="http://en.wikipedia.org/wiki/Alpha_compositing" title="http://en.wikipedia.org/wiki/Alpha_compositing"><em>alpha channel</em></a> values must be used when applying it.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<p>Let's apply the following rectangle as a mask:</p>
<pre class="brush: html">
&lt;rect x="10" y="10" width="80" height="80" fill="red" fill-opacity="0.7" /&gt;</pre>
<h3 id="mask" style="display:none">mask</h3>
<pre class="brush: html" style="display:none">
&lt;svg&gt;
&lt;rect x="10" y="10" width="80" height="80" fill="red" fill-opacity="0.7"/&gt;
&lt;/svg&gt;</pre>
<div>
  which leads to the following square: {{ EmbedLiveSample('mask', '100%', '100') }}</div>
<h3 id="box" style="display:none">box</h3>
<p>to this box:</p>
<pre class="brush: css" style="display:none">
.redsquare {
&nbsp;&nbsp;&nbsp; height: 100px;
&nbsp;&nbsp;&nbsp; width: 100px;
&nbsp;&nbsp;&nbsp; background-color: rgb(128, 128, 128);
&nbsp;&nbsp;&nbsp; border: solid 1px black;
}
</pre>
<pre class="brush: html" style="display:none">
&lt;div class="redsquare"&gt;&lt;/div&gt;
</pre>
<div>
  {{ EmbedLiveSample('box', '100%', '100') }}</div>
<h3 id="result" style="display:none">result</h3>
<p>The result, if your browser supports the property, with different value of <code>mask-type</code> applied to the {{SVGElement("mask")}} element are these two different squares:</p>
<table class="standard-table">
  <tbody>
    <tr>
      <td><code>mask-type: alpha;</code></td>
      <td><code>mask-type: luminance;</code></td>
    </tr>
    <tr>
      <td>
        <div id="maskalpha" style="display:none">
          <pre class="brush: html">
&lt;div class="redsquare"&gt;&lt;/div&gt;
&lt;svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
&nbsp;&nbsp;&nbsp; &lt;defs&gt;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mask id="m" maskContentUnits="objectBoundingBox" style="mask-type:alpha"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;rect x=".1" y=".1" width=".8" height=".8" fill="red" fill-opacity="0.7"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/mask&gt;
&nbsp; &lt;/defs&gt;
&lt;/svg&gt;
</pre>
          <pre class="brush: css">
.redsquare {
&nbsp;&nbsp;&nbsp; height: 100px;
&nbsp;&nbsp;&nbsp; width: 100px;
&nbsp;&nbsp;&nbsp; background-color: rgb(128, 128, 128);
&nbsp;&nbsp;&nbsp; border: solid 1px black;
    mask: url("#m");
}
</pre>
        </div>
        <div>
          {{ EmbedLiveSample('maskalpha', '100%', '100') }}</div>
      </td>
      <td>
        <div id="maskluminance" style="display:none">
          <pre class="brush: html">
&lt;div class="redsquare"&gt;&lt;/div&gt;
&lt;svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
&nbsp;&nbsp;&nbsp; &lt;defs&gt;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mask id="m" maskContentUnits="objectBoundingBox" style="mask-type:luminance"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;rect x=".1" y=".1" width=".8" height=".8" fill="red" fill-opacity="0.7"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/mask&gt;
&nbsp; &lt;/defs&gt;
&lt;/svg&gt;
</pre>
          <pre class="brush: css">
.redsquare {
&nbsp;&nbsp;&nbsp; height: 100px;
&nbsp;&nbsp;&nbsp; width: 100px;
&nbsp;&nbsp;&nbsp; background-color: rgb(128, 128, 128);
&nbsp;&nbsp;&nbsp; border: solid 1px black;
    mask: url("#m");
}
</pre>
        </div>
        <div>
          {{ EmbedLiveSample('maskluminance', '100%', '100') }}</div>
      </td>
    </tr>
  </tbody>
</table>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS Masks', '#mask-type', 'mask') }}</td>
      <td>{{ Spec2('CSS Masks') }}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>24.0</td>
        <td>{{CompatGeckoDesktop("20.0")}}</td>
        <td>{{ CompatNo() }}</td>
        <td>15.0</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{CompatGeckoMobile("20.0")}}</td>
        <td>{{ CompatNo() }}</td>
        <td>15.0</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li>Other mask-related properties: {{cssxref("mask")}}</li>
</ul>
Revert to this revision