docs.rodeo

MDN Web Docs mirror

mask-size

{{CSSRef}} 

The mask-size CSS property specifies the sizes of the mask images. The size of the image can be fully or partially constrained in order to preserve its intrinsic ratio.

[!NOTE] If the value of this property is not set in a {{cssxref("mask")}}  shorthand property that is applied to the element after the mask-size CSS property, the value of this property is then reset to its initial value by the shorthand property.

Syntax

/* Keywords syntax */
mask-size: cover;
mask-size: contain;

/* One-value syntax */
/* the width of the image (height set to 'auto') */
mask-size: 50%;
mask-size: 3em;
mask-size: 12px;
mask-size: auto;

/* Two-value syntax */
/* first value: width of the image, second value: height */
mask-size: 50% auto;
mask-size: 3em 25%;
mask-size: auto 6px;
mask-size: auto auto;

/* Multiple values */
/* Do not confuse this with mask-size: auto auto */
mask-size: auto, auto;
mask-size: 50%, 25%, 25%;
mask-size: 6px, auto, contain;

/* Global values */
mask-size: inherit;
mask-size: initial;
mask-size: revert;
mask-size: revert-layer;
mask-size: unset;

One or more <bg-size> values, separated by commas.

A <bg-size> can be specified in one of three ways:

To specify a size using width and height, you can supply one or two values:

Each value can be a <length>, a <percentage>, or auto.

Values

The interpretation of possible values depends on the image’s intrinsic dimensions (width and height) and intrinsic proportion (ratio of width and height). A bitmap image always has intrinsic dimensions and an intrinsic proportion. A vector image may have both intrinsic dimensions and thus it has an intrinsic proportion too. It also may have one or no intrinsic dimensions and in either case it might or might not have an intrinsic proportion. Gradients are treated as images with no intrinsic dimensions or intrinsic proportion.

The rendered size of the mask image is then computed as follows:

Formal definition

{{cssinfo}} 

Formal syntax

{{csssyntax}} 

Examples

Setting mask size as a percentage

<div class="masked"></div>
.masked {
  width: 200px;
  height: 200px;
  background: blue linear-gradient(red, blue);
  margin-bottom: 10px;

  mask-image: url(https://mdn.github.io/shared-assets/images/examples/mdn.svg);
  mask-size: 50%;
}

{{EmbedLiveSample("mask-size-example", "", "250px")}} 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN