CSS mask-position Property

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

What You’ll Learn

The mask-position property defines where a mask-image is placed inside an element — using the same keywords, percentages, and lengths as background-position.

01

Placement

Move the mask image.

02

Keywords

top, left, center.

03

Percentages

Relative positioning.

04

Pixels

Exact distances.

05

WebKit

Prefix for Safari.

06

Related

mask-size, repeat.

Introduction

The mask-position property in CSS defines the position of a mask image within an element. Masking allows you to hide or reveal specific parts of an element based on the transparency and position of the mask image.

This property is especially useful for creating complex shapes, patterns, and visual effects by positioning the mask precisely. Pair it with mask-image, mask-size, and mask-repeat for full control.

Definition and Usage

Use mask-position: center to center a silhouette mask, top left for corner placement, or percentages and pixels for fine-tuned offsets. The syntax mirrors background-position, so if you know one, the other feels familiar.

💡
Beginner Tip

Set mask-repeat: no-repeat and a fixed mask-size first — then change only mask-position to clearly see how the mask moves inside the element.

📝 Syntax

The syntax for the mask-position property is similar to background-position. It accepts horizontal and vertical position values:

syntax.css
element {
  mask-position: x-position y-position;
}
  • x-position — specifies the horizontal position of the mask image.
  • y-position — specifies the vertical position of the mask image.

Basic Example

mask-position.css
.masked {
  width: 300px;
  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-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

Syntax Rules

  • The initial value is 0% 0% (top-left corner).
  • mask-position only applies when a mask-image is set.
  • Keywords include top, left, bottom, right, and center.
  • Length units like px and em, and percentages, are also supported.
  • Include -webkit-mask-position alongside mask-position for broader Safari support.

⚡ Quick Reference

QuestionAnswer
Initial value0% 0% (top-left)
Applies toAll elements
InheritedNo
AnimatableYes, when interpolable
Common useCentering masks, corner placement, offset silhouettes

💎 Property Values

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

ValueExampleMeaning
Keywordsmask-position: center;Predefined positions like top, left, bottom, right, center.
Lengthmask-position: 20px 30px;Specifies the position using length units like px, em, etc.
Percentagemask-position: 50% 50%;Specifies the position as a percentage of the mask container’s dimensions.
initialmask-position: initial;Resets to the default value (0% 0%)
inheritmask-position: inherit;Inherits the mask position from the parent element
center top left 50% 50% 20px 30px

🎯 Default Value

The default value of the mask-position property is 0% 0%, which places the mask image at the top-left corner of the element.

Common Position Values

TypeExampleBest for
Single keywordcenterQuick centering of a mask silhouette
Two keywordstop left, bottom rightCorner and edge placement
Percentages50% 50%, 75% 25%Responsive placement relative to element size
Pixel lengths20px 30pxPrecise decorative offsets

👀 Live Preview

The same gradient and PNG mask with three position values — only the placement changes:

center
top left
bottom right

Use mask-repeat: no-repeat and a fixed mask-size to make placement differences easy to see.

Examples Gallery

Position a mask image at the center, in corners, with percentages, and compare multiple placement values side by side.

🖼 Mask Placement

Start with the reference example — center a mask image inside the element.

Example 1 — Centered Mask

Position a mask image at the center of an element with mask-position: center.

mask-position.html
<style>
  .masked {
    width: 300px;
    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-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
  }
</style>

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

How It Works

mask-position: center places the mask image at the center of the element — the most common choice for logo and silhouette masks.

Example 2 — Corner Keywords

Use keyword pairs like top left or bottom right to anchor the mask to a corner.

mask-position-corners.html
<style>
  .mask-corner {
    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-size: 80px;
    mask-size: 80px;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: top left;
    mask-position: top left;
  }
</style>

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

How It Works

top left anchors the mask to the top-left corner. Try bottom right to move it to the opposite corner.

🛠 Percentages & Comparison

Use relative percentages for responsive placement, then compare multiple position values.

Example 3 — Percentage Position

Use percentages to position the mask relative to the element size — for example, 75% 25% moves it toward the upper-right area.

mask-position-percent.html
<style>
  .mask-percent {
    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-size: 70px;
    mask-size: 70px;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: 75% 25%;
    mask-position: 75% 25%;
  }
</style>

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

How It Works

Percentages position the mask relative to the element’s width and height. 50% 50% is equivalent to center for many mask sizes.

Example 4 — Position Values Compared

Side-by-side comparison of center, top left, and bottom right with the same mask:

mask-position-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-size: 56px;
  mask-size: 56px;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}
.pos-center { mask-position: center; }
.pos-top-left { mask-position: top left; }
.pos-bottom-right { mask-position: bottom right; }
Try It Yourself

How It Works

With the same mask size and no repeat, changing only mask-position moves the silhouette to a different spot inside each box.

♿ Accessibility

  • Set mask-image firstmask-position 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 different sizes — Pair mask-position with mask-size to see how placement changes at various dimensions.
  • Check contrast — Partially masked areas can reduce readability if text sits over them.
  • Offer fallbacks — Ensure content remains usable when masking is unsupported.

mask-position vs background-position

Featuremask-positionbackground-position
ControlsWhere the mask image sits within the mask areaWhere the background image sits within the background area
Default value0% 0% (top-left)0% 0% (top-left)
ValuesKeywords, percentages, lengthsKeywords, percentages, lengths
Typical useShift a mask shape to reveal or hide parts of an elementAlign a decorative background image

🧠 How mask-position Works

1

You set a mask-image

Define the mask source with mask-image first.

Mask source
2

You choose a position

Use keywords like center, percentages like 75% 25%, or lengths like 20px 10px.

Position values
3

Browser places the mask

The mask image is aligned within the mask positioning area defined by mask-origin and sized with mask-size.

Coordinate mapping
=

Precisely placed mask

The mask shape appears exactly where you specified, revealing or hiding the right parts of the element.

🖥 Browser Compatibility

The mask-position property is supported in most modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. Include -webkit-mask-position for Safari, and test across browsers to ensure your mask placement looks correct.

Baseline · Modern browsers

Mask position in modern browsers

Keywords, percentages, 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-position property 95% supported

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

🎉 Conclusion

The mask-position property is a versatile tool for web designers and developers looking to create unique and visually engaging masked effects.

By controlling where the mask image sits, you can manipulate which parts of an element are visible. Experiment with keywords, percentages, and pixel values to achieve the effect you want.

💡 Best Practices

✅ Do

  • Use center for a quick, balanced mask placement
  • Combine keywords like top left for corner alignment
  • Use percentages for responsive mask placement that scales with the element
  • Always set mask-image before applying mask-position
  • Include -webkit-mask-position alongside mask-position

❌ Don’t

  • Set mask-position without a mask-image
  • Confuse mask-position with mask-origin — position moves the mask; origin sets the positioning area
  • Hide essential text or controls with masks
  • Forget WebKit prefixes when targeting Safari users
  • Expect visible movement when mask-size: cover fills the entire area

Key Takeaways

Knowledge Unlocked

Five things to remember about mask-position

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

5
Core concepts
02

Keywords

center, top left.

Common
% 03

Percentages

Scale with size.

Flexible
img 04

Like background-position

Same syntax.

Familiar
web 05

WebKit prefix

Safari support.

Compat

❓ Frequently Asked Questions

The mask-position property defines where a mask image is placed within an element. It works like background-position but applies to the mask-image layer.
The default value is 0% 0%, which places the mask image at the top-left corner of the mask positioning area.
They use the same syntax and values, but mask-position moves the mask-image layer while background-position moves the background-image layer.
No. mask-position only affects placement when a mask-image is set. You must define the mask source first.
Yes. Keywords like center, top left, and bottom right are common values, just like with background-position.

Practice in the Live Editor

Open the HTML editor, try mask-position with center, top left, and percentage 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