1. css
  2. /properties
  3. /mask-type

mask-type

Definition

The mask-type CSS property specifies the type of mask to be used on an element. It determines how a mask image should be treated, whether it is treated as an alpha mask or a luminance mask.

Examples

In this example, we set the mask-type property to luminance and apply a mask image to a div element. This means that the luminance values of the mask image will be used to create the mask, rather than the alpha channel:

<div class="masked"></div>
.masked {
  width: 200px;
  height: 200px;
  background-color: red;
  mask-image: url('mask-image.png');
  mask-type: luminance;
}

In this example, we set the mask-type property to alpha and apply a mask image to a div element. This means that the alpha channel of the mask image will be used to create the mask:

<div class="masked"></div>
.masked {
  width: 200px;
  height: 200px;
  background-color: red;
  mask-image: url('mask-image.png');
  mask-type: alpha;
}

Values

ValueDescription
alphaSpecifies that the alpha channel of the mask image should be used to create the mask.
luminanceSpecifies that the luminance values of the mask image should be used to create the mask.

Best Practices

  • Choose the appropriate value for your use case: The mask-type property allows you to specify whether the alpha channel or the luminance values of the mask image should be used to create the mask. Choose the appropriate value based on your use case and the effect you are trying to achieve.
  • Test in different browsers: The mask-type property is supported in most modern browsers, but it's still a good idea to test your code in different browsers to ensure cross-browser compatibility.
  • Use a high-quality mask image: The effectiveness of the mask image depends on its quality. Make sure the mask image is high-quality, with sharp edges and good contrast.
  • Experiment with different values: The mask-type property is just one of many properties you can use to achieve masking effects. Experiment with different values to achieve the effect you want.
  • Consider performance: Masking can be computationally expensive, especially when using large images or complex masks. Consider the performance implications of using the mask-type property, and optimize your code accordingly.
  • Use fallbacks for unsupported browsers: If you are using the mask-type property and other masking properties, make sure to provide fallbacks for browsers that do not support these features. One approach is to use a solid color as a fallback.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesNoYesYes