CSS mask-origin Property

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

What You’ll Learn

The mask-origin property defines the positioning area for a mask-image — similar to how background-origin works for backgrounds.

01

border-box

Default origin area.

02

padding-box

Inside the border.

03

content-box

Inner content only.

04

With mask-image

Requires a mask layer.

05

WebKit

Prefix for Safari.

06

Related

mask-position, size.

Introduction

The mask-origin property in CSS defines the origin of the mask image used on an element. It determines the positioning area for the mask — similar to the background-origin property for background images.

This property is particularly useful when you want to control how the mask image is applied to an element’s content box, padding box, or border box. Pair it with mask-image, mask-size, and mask-position for precise mask placement.

Definition and Usage

Use mask-origin: border-box (the default) when the mask should align with the outer edge including the border. Use padding-box to start positioning inside the border, or content-box when the mask should align only with the inner content area.

💡
Beginner Tip

Add a visible border and padding to your element, then switch between border-box, padding-box, and content-box — the mask will shift relative to each box edge, making the difference easy to see.

📝 Syntax

The syntax for the mask-origin property uses one of three box-model keyword values:

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

Here, value can be one of the specified keywords: border-box, padding-box, or content-box.

Basic Example

mask-origin.css
.masked-element {
  width: 300px;
  height: 200px;
  padding: 20px;
  border: 10px solid #334155;
  background: url('/images/valley-pattern.jpg') center/cover;
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-origin: padding-box;
  mask-origin: padding-box;
}

Syntax Rules

  • The initial value is border-box.
  • mask-origin only applies when a mask-image is set.
  • border-box includes the border area in the positioning reference.
  • padding-box starts positioning at the outer edge of the padding (inside the border).
  • Include -webkit-mask-origin alongside mask-origin for broader Safari support.

⚡ Quick Reference

QuestionAnswer
Initial valueborder-box
Applies toAll elements
InheritedNo
AnimatableNo
Common useAligning mask-image positioning to border, padding, or content edges

💎 Property Values

The mask-origin property accepts three box-model keyword values that define the mask positioning area.

ValueExampleMeaning
border-boxmask-origin: border-box;The mask image is positioned relative to the border box (default).
padding-boxmask-origin: padding-box;The mask image is positioned relative to the padding box, inside the border.
content-boxmask-origin: content-box;The mask image is positioned relative to the content box only.
initialmask-origin: initial;Resets to the default value (border-box)
inheritmask-origin: inherit;Inherits the mask origin from the parent element
border-box padding-box content-box

🎯 Default Value

The default value of the mask-origin property is border-box, which means the mask image is positioned relative to the border box of the element by default.

Positioning Areas

ValuePositioning starts atBest for
border-boxOuter edge of the borderDefault behavior; mask spans the full element including border
padding-boxOuter edge of the padding (inside border)Mask aligned inside the border, like the reference example
content-boxInner edge of the paddingMask confined to the content area only

👀 Live Preview

The same gradient and PNG mask with three origin values — notice how the mask shifts relative to the border and padding:

border-box
padding-box
content-box

Examples Gallery

Apply a mask image and use mask-origin to control where the mask positioning area begins — then compare all three box values side by side.

🖼 Mask Origins

Start with the reference example — position the mask relative to the padding box instead of the default border box.

Example 1 — padding-box Origin

Apply a mask image and set mask-origin: padding-box so the mask is positioned relative to the padding area, inside the border.

mask-origin.html
<style>
  .masked-element {
    width: 280px;
    height: 200px;
    padding: 20px;
    border: 10px solid #334155;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-origin: padding-box;
    mask-origin: padding-box;
  }
</style>

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

How It Works

The mask image is positioned relative to the padding box rather than the default border box. With visible border and padding, the mask sits inset from the outer border edge.

Example 2 — border-box (Default)

The default border-box value positions the mask relative to the outer edge of the border — the full element box including border area.

mask-origin-border.html
<style>
  .mask-border {
    width: 280px;
    height: 200px;
    padding: 20px;
    border: 10px solid #334155;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-origin: border-box;
    mask-origin: border-box;
  }
</style>

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

How It Works

Because this is the default, you often do not need to set it explicitly. The mask positioning area starts at the outer border edge, so the mask can extend into the border region.

🛠 Content Box & Comparison

Confine the mask to the content area and compare all three origin values together.

Example 3 — content-box Origin

Use mask-origin: content-box when the mask should align only with the inner content area, excluding padding and border.

mask-origin-content.html
<style>
  .mask-content {
    width: 280px;
    height: 200px;
    padding: 20px;
    border: 10px solid #334155;
    background: url('/images/valley-pattern.jpg') center/cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-origin: content-box;
    mask-origin: content-box;
  }
</style>

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

How It Works

The mask positioning area is the content box only. Padding and border sit outside the mask origin, so the mask appears further inset than with padding-box or border-box.

Example 4 — All Three Origins Compared

Side-by-side comparison of border-box, padding-box, and content-box with the same mask and visible border:

mask-origin-compare.css
.mask-box {
  padding: 20px;
  border: 10px solid #334155;
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-size: 60px;
  mask-size: 60px;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: top left;
  mask-position: top left;
}
.origin-border { mask-origin: border-box; }
.origin-padding { mask-origin: padding-box; }
.origin-content { mask-origin: content-box; }
Try It Yourself

How It Works

Each box shifts the mask origin inward. With mask-position: top left, the mask anchor moves further right and down as you go from border-box to content-box.

♿ Accessibility

  • Set mask-image firstmask-origin 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 with visible padding — Add border and padding to see how each origin value shifts the mask.
  • Check contrast — Partially masked areas can reduce readability if text sits over them.
  • Offer fallbacks — Ensure content remains usable when masking is unsupported.

mask-origin vs background-origin

Featuremask-originbackground-origin
ControlsMask image positioning areaBackground image positioning area
Default valueborder-boxpadding-box
Valuesborder-box, padding-box, content-boxborder-box, padding-box, content-box
Typical useAlign mask-image to element boxesAlign background-image to element boxes

🧠 How mask-origin Works

1

You set a mask-image

Define the mask source with mask-image first.

Mask source
2

You choose an origin box

Pick border-box, padding-box, or content-box for the positioning area.

Origin selection
3

Browser positions the mask

mask-size and mask-position are calculated from the chosen box edge.

Box mapping
=

Precisely placed mask

The mask aligns to the border, padding, or content edge you specified.

🖥 Browser Compatibility

The mask-origin property is supported in most modern browsers, including Chrome, Firefox, Safari, and Edge. Include -webkit-mask-origin for Safari, and test with border and padding to verify positioning.

Baseline · Modern browsers

Mask origin in modern browsers

All three box values 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-origin property 90% supported

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

🎉 Conclusion

The mask-origin property is a valuable tool for web developers looking to control the positioning of mask images in relation to an element’s boxes.

By understanding and using this property, you can create more precise and visually appealing designs. Experiment with different values and see how they affect the appearance of your masked elements.

💡 Best Practices

✅ Do

  • Use border-box for the default full-element mask positioning
  • Use padding-box to align the mask inside the border
  • Use content-box when only the inner content area should anchor the mask
  • Always set mask-image before applying mask-origin
  • Include -webkit-mask-origin alongside mask-origin

❌ Don’t

  • Set mask-origin without a mask-image
  • Confuse mask-origin with mask-clip — origin sets positioning, clip sets painting
  • Hide essential text or controls with masks
  • Forget WebKit prefixes when targeting Safari users
  • Expect visible shifts without padding or border on the element

Key Takeaways

Knowledge Unlocked

Five things to remember about mask-origin

Use these points when choosing the mask positioning area.

5
Core concepts
02

padding-box

Inside border.

Common
box 03

content-box

Inner content only.

Precise
img 04

Needs mask-image

Requires a mask layer.

Dependency
web 05

WebKit prefix

Safari support.

Compat

❓ Frequently Asked Questions

The mask-origin property defines the positioning area for a mask image. It controls whether the mask is positioned relative to the border box, padding box, or content box of an element.
The default value is border-box, meaning the mask image is positioned relative to the outer edge of the element's border by default.
They work the same way but apply to different layers. mask-origin sets the positioning area for mask-image, while background-origin sets it for background-image.
No. mask-origin only affects how an existing mask-image is positioned. You must set mask-image first.
Use content-box when you want the mask aligned to the inner content area, ignoring padding and border — useful when padding should stay fully visible outside the mask.

Practice in the Live Editor

Open the HTML editor, try mask-origin with border-box, padding-box, and content-box, 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