CSS Portal

CSS mask-size Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The mask-size property controls how an element’s mask image(s) are scaled when they are painted over the element. It determines the rendered dimensions of the mask content relative to the mask positioning area, which in turn affects which parts of the underlying element remain visible or hidden. Because a mask is effectively a coverage map (alpha or luminance values that modulate an element’s opacity), changing the mask’s scale can dramatically alter edges, gradients, and the apparent softness or hardness of transitions between visible and masked-away regions.

Scaling behavior must be considered alongside the source of the mask itself — for example, whether the mask comes from an image, an SVG, or a CSS gradient — since different sources have different intrinsic sizes and aspect ratios. The chosen scale interacts with the mask resource specified via mask-image; when a mask image has an intrinsic size, mask-size decides whether that intrinsic size is preserved, stretched, or reduced. It also works together with mask-repeat, because scaled-down masks that repeat will tile differently than full-size or scaled-up ones, and scaled-up repeating masks can introduce unexpected seams or interpolation artifacts.

Conceptually, mask-size behaves much like the sizing controls used for background artwork; authors familiar with background-size will find the mental model similar: you are controlling how large the mask paint is relative to the element. Positioning and anchoring of that scaled mask are then handled separately (see mask-position), so it’s common to think of sizing and positioning as two distinct steps — first establish how large the mask should be, then where it should sit inside the element. This separation lets you create responsive masking effects: for example, scaling a mask proportionally to the element’s size or fixing the mask to a specific pixel size regardless of the element’s dimensions.

In practical terms, using mask-size lets you create a wide range of visual effects: crisp cutouts or soft feathered edges by shrinking or enlarging a gradient mask, repeating patterned masks at a controlled scale, or fitting vector masks to a particular area without distortion. When layering multiple masks, each layer’s size can be controlled independently, enabling complex composite masking. Because scaling can introduce interpolation and anti-aliasing, designers often combine careful sizing with appropriate mask sources and repetition/position choices to preserve clarity and achieve the intended visual result.

Definition

Initial value
auto
Applies to
all elements; In SVG, it applies to container elements excluding the <defs> element and all graphics elements
Inherited
no
Computed value
as specified, but with relative lengths converted into absolute lengths
Animatable
yes
JavaScript syntax
object.style.maskSize

Syntax

mask-size: auto | cover | contain | <length> | <percentage> | [ <length> | <percentage> ]{1,2} ;

Values

  • auto The mask image keeps its original size. If only one value is given, the other is auto.
  • cover Scales the mask image to fully cover the element’s box, potentially cropping parts of the mask.
  • contain Scales the mask image to fit inside the element’s box, maintaining aspect ratio without cropping.
  • <length>Specifies an exact width and/or height for the mask image. If only one value is provided, the other is auto.
  • <percentage>Sizes the mask image relative to the element’s dimensions.
  • (Two Values)The first value sets the width, the second sets the height. Each can be a keyword, length, or percentage.

Example

<div class="wrap">
<div class="item">
<div class="box cover">cover</div>
<div class="label">mask-size: cover</div>
</div>

<div class="item">
<div class="box contain">contain</div>
<div class="label">mask-size: contain</div>
</div>

<div class="item">
<div class="box explicit">50% 50%</div>
<div class="label">mask-size: 50% 50%</div>
</div>
</div>
/* Layout */
.wrap {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    padding: 24px;
    background: #f4f6f8;
}
.item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
}
.label {
    color: #333;
    font-size: 14px;
}

/* Masked boxes */
.box {
    width: 200px;
    height: 200px;
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.95);
    font-weight: 700;
    letter-spacing: 0.6px;
    border-radius: 12px;

    /* colorful background so the mask effect is visible */
    background: linear-gradient(135deg, #ff7a18 0%, #af002d 50%, #319197 100%);

    /* Use the same inline SVG mask for all boxes */
    -webkit-mask-image: url('data:image/svg+xml;utf8,');
    mask-image: url('data:image/svg+xml;utf8,');

    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;

    /* Make the text visible on top of the masked shape */
    box-shadow: 0 6px 18px rgba(10, 20, 30, 0.08);
}

/* Different mask-size values demonstrated */
.cover {
    -webkit-mask-size: cover;
    mask-size: cover;
}
.contain {
    -webkit-mask-size: contain;
    mask-size: contain;
}
.explicit {
    -webkit-mask-size: 50% 50%;
    mask-size: 50% 50%;
}

Browser Support

The following information will show you the current browser support for the CSS mask-size property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!