CSS mask-size Property

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
Visual Effects

What You’ll Learn

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.

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.

📝 Syntax

The syntax for the mask-size property accepts one or two values for width and height:

syntax.css
element {
  mask-size: value;
}

Basic Example

mask-size.css
.masked-element {
  width: 300px;
  height: 300px;
  background: url('/images/valley-pattern.jpg') center/cover;
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: cover;
  mask-size: cover;
}

Syntax Rules

  • 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.

⚡ Quick Reference

QuestionAnswer
Initial valueauto
Applies toAll elements
InheritedNo
AnimatableNo
Common useFull-element masks, logo silhouettes, tiled pattern dimensions

💎 Property Values

The mask-size property accepts keywords, lengths, and percentages — the same value types as background-size.

ValueExampleMeaning
automask-size: auto;The mask image is displayed at its intrinsic size.
Lengthmask-size: 80px;Specifies width and height using length units like px or em.
Percentagemask-size: 50%;Specifies the mask size as a percentage of the element’s dimensions.
covermask-size: cover;Scales the mask to cover the entire element; may clip edges.
containmask-size: contain;Scales the mask to fit inside the element without clipping.
initialmask-size: initial;Resets to the default value (auto)
inheritmask-size: inherit;Inherits the mask size from the parent element
cover contain 80px 50%

🎯 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.

Common Size Values

ValueExampleBest for
coverFill elementFull-element silhouette masks that may clip at edges
containFit insideShowing the entire mask shape without clipping
Fixed pixels48px, 80pxSmall tiles for repeating patterns
Percentages50%, 100% 80%Responsive mask sizing relative to the element

👀 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.

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.

mask-size.html
<style>
  .masked-element {
    width: 300px;
    height: 300px;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: cover;
    mask-size: cover;
  }
</style>

<div class="masked-element"></div>
Try It Yourself

How It Works

mask-size: cover scales the mask to fill the element while keeping aspect ratio — edges may be clipped, just like background-size: cover.

Example 2 — Contain (No Clipping)

Fit the entire mask shape inside the element with mask-size: contain.

mask-size-contain.html
<style>
  .mask-contain {
    width: 280px;
    height: 200px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
  }
</style>

<div class="mask-contain"></div>
Try It Yourself

How It Works

contain keeps the full mask shape visible inside the element. Use it when clipping would cut off important parts of the silhouette.

🛠 Fixed Size & Comparison

Set an exact pixel size, then compare cover, contain, and fixed dimensions.

Example 3 — Fixed Pixel Size

Set an exact mask dimension with mask-size: 80px — useful for small tiles and precise silhouettes.

mask-size-fixed.html
<style>
  .mask-fixed {
    width: 280px;
    height: 200px;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: 80px;
    mask-size: 80px;
  }
</style>

<div class="mask-fixed"></div>
Try It Yourself

How It Works

A single length sets both width and height. Pair a small fixed size with mask-repeat: repeat to build tile patterns.

Example 4 — Size Values Compared

Side-by-side comparison of cover, contain, and 48px with the same mask:

mask-size-compare.css
.mask-box {
  width: 200px;
  height: 140px;
  background: linear-gradient(135deg, #f97316, #ec4899);
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
.sz-cover { mask-size: cover; }
.sz-contain { mask-size: contain; }
.sz-fixed { mask-size: 48px; }
Try It Yourself

How It Works

With the same mask image and no repeat, changing only mask-size switches between a filled silhouette, a fitted shape, and a small icon-sized mask.

♿ Accessibility

  • Set mask-image firstmask-size has no effect without an active mask layer.
  • Do not hide essential content — Masked-away text or controls may be invisible but still exist in the DOM.
  • Test cover vs contain — Compare both values to see clipping vs full-shape visibility.
  • Check contrast — Partially masked areas can reduce readability if text sits over them.
  • Offer fallbacks — Ensure content remains usable when masking is unsupported.

mask-size vs background-size

Featuremask-sizebackground-size
ControlsHow large the mask image is drawn within the mask areaHow large the background image is drawn within the background area
Default valueautoauto
Valuesauto, cover, contain, lengths, percentagesauto, cover, contain, lengths, percentages
Typical useScale silhouette masks or set tile dimensions for patternsScale decorative background images and textures

🧠 How mask-size Works

1

You set a mask-image

Define the mask source with mask-image first.

Mask source
2

You choose a size

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.

🖥 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 Chrome 55+ · Desktop & Mobile
Full support
Mozilla Firefox 54+ · Desktop & Mobile
Full support
Apple Safari 9.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 42+ · Modern versions
Full support
mask-size property 95% supported

Bottom line: Safe for modern projects. Pair mask-size with -webkit-mask-size and test PNG masks in Safari.

🎉 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.

💡 Best Practices

✅ Do

  • Use cover to fill the element with the mask shape
  • Use contain when the full mask shape must stay visible
  • Use fixed pixels like 48px for small tiles in repeating patterns
  • Always set mask-image before applying mask-size
  • Include -webkit-mask-size alongside mask-size

❌ Don’t

  • Set mask-size without a mask-image
  • Confuse mask-size with mask-repeat — size controls dimensions; repeat controls tiling
  • Hide essential text or controls with masks
  • Forget WebKit prefixes when targeting Safari users
  • Expect visible size changes when the mask already fills the element at default auto

Key Takeaways

Knowledge Unlocked

Five things to remember about mask-size

Use these points when scaling a mask image on an element.

5
Core concepts
02

cover

Fill element.

Common
03

contain

No clipping.

Safe fit
px 04

Like background-size

Same keywords.

Familiar
web 05

WebKit prefix

Safari support.

Compat

❓ Frequently Asked Questions

The mask-size property defines how large a mask image is drawn within an element. It works like background-size but applies to the mask-image layer.
The default value is auto, which displays the mask at its intrinsic size or scales it based on mask-repeat behavior.
They accept the same keyword and length values, but mask-size controls the mask-image layer while background-size controls the background-image layer.
No. mask-size only affects sizing when a mask-image is set. You must define the mask source first.
Use cover to fill the entire element with the mask (may clip edges). Use contain to show the full mask shape without clipping (may leave empty space).

Practice in the Live Editor

Open the HTML editor, try mask-size with cover, contain, and fixed pixel values, and preview effects instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful