The mask-size property defines how large a mask-image is drawn — using the same keywords and lengths as background-size.
01
Sizing
Scale the mask image.
02
cover
Fill the element.
03
contain
Fit without clipping.
04
Pixels / %
Exact dimensions.
05
WebKit
Prefix for Safari.
06
Related
repeat, position.
Fundamentals
Introduction
The mask-size property in CSS defines the size of an element’s mask image. Masks hide or reveal parts of an element using an image or graphical representation.
By setting the mask size, you control how the image fits the element and how it affects the visibility of the underlying content. Pair it with mask-image, mask-repeat, and mask-position for full control.
Definition and Usage
Use mask-size: cover to fill the element with the mask, contain to show the full shape without clipping, or pixel and percentage values for precise dimensions. The syntax mirrors background-size, so if you know one, the other feels familiar.
💡
Beginner Tip
Set mask-repeat: no-repeat first — then change only mask-size to clearly see how cover, contain, and fixed sizes differ.
Foundation
📝 Syntax
The syntax for the mask-size property accepts one or two values for width and height:
The initial value is auto (intrinsic mask image size).
mask-size only applies when a mask-image is set.
Keywords include cover, contain, and auto.
Length units like px and percentages set explicit width and height.
Include -webkit-mask-size alongside mask-size for broader Safari support.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
auto
Applies to
All elements
Inherited
No
Animatable
No
Common use
Full-element masks, logo silhouettes, tiled pattern dimensions
Reference
💎 Property Values
The mask-size property accepts keywords, lengths, and percentages — the same value types as background-size.
Value
Example
Meaning
auto
mask-size: auto;
The mask image is displayed at its intrinsic size.
Length
mask-size: 80px;
Specifies width and height using length units like px or em.
Percentage
mask-size: 50%;
Specifies the mask size as a percentage of the element’s dimensions.
cover
mask-size: cover;
Scales the mask to cover the entire element; may clip edges.
contain
mask-size: contain;
Scales the mask to fit inside the element without clipping.
initial
mask-size: initial;
Resets to the default value (auto)
inherit
mask-size: inherit;
Inherits the mask size from the parent element
covercontain80px50%
Default
🎯 Default Value
The default value of the mask-size property is auto, which means the mask image is displayed at its intrinsic size or scaled to fit the element, depending on the mask-repeat property.
Value Types
Common Size Values
Value
Example
Best for
cover
Fill element
Full-element silhouette masks that may clip at edges
contain
Fit inside
Showing the entire mask shape without clipping
Fixed pixels
48px, 80px
Small tiles for repeating patterns
Percentages
50%, 100% 80%
Responsive mask sizing relative to the element
Preview
👀 Live Preview
The same gradient and PNG mask with three size values — only the scale changes:
cover
contain
48px
Use mask-repeat: no-repeat so size differences are easy to compare.
Hands-On
Examples Gallery
Scale a mask to cover the element, fit inside without clipping, use fixed pixels, and compare multiple size values side by side.
🖼 Mask Scaling
Start with the reference example — scale the mask to cover the entire element.
Example 1 — Cover the Element
Scale a mask image to cover the entire element with mask-size: cover.
Use cover, contain, pixels like 80px, or percentages like 50%.
Size values
3
Browser scales the mask
The mask image is drawn at the specified size, then positioned with mask-position and tiled with mask-repeat.
Scaling logic
=
🖼
Correctly scaled mask
The mask appears at the size you specified — filling the element, fitting inside, or at an exact dimension.
Compatibility
🖥 Browser Compatibility
The mask-size property is supported in most modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. Include -webkit-mask-size for Safari, and test across browsers to ensure your mask scaling looks correct.
✓ Baseline · Modern browsers
Mask size in modern browsers
cover, contain, auto, and length values all work in major browsers. Use the WebKit prefix for best Safari coverage.
95%Modern browser support
Google Chrome55+ · Desktop & Mobile
Full support
Mozilla Firefox54+ · Desktop & Mobile
Full support
Apple Safari9.1+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Opera42+ · Modern versions
Full support
mask-size property95% supported
Bottom line: Safe for modern projects. Pair mask-size with -webkit-mask-size and test PNG masks in Safari.
Wrap Up
🎉 Conclusion
The mask-size property is a versatile tool for web developers looking to create intricate designs and masked effects.
By controlling the size of a mask image, you can precisely determine how it interacts with the content it covers. Experiment with cover, contain, and pixel values to achieve unique and visually appealing results.