The mask-position CSS property sets the initial position, relative to the mask position layer set by mask-origin, for each defined mask image.
mask-position
Baseline 2023
Newly available
Since December 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Syntax
/* Keyword values */ mask-position: top; mask-position: bottom; mask-position: left; mask-position: right; mask-position: center; /* <position> values */ mask-position: 25% 75%; mask-position: 0px 0px; mask-position: 10% 8em; /* Multiple values */ mask-position: top right; mask-position: 1rem 1rem, center; /* Global values */ mask-position: inherit; mask-position: initial; mask-position: revert; mask-position: revert-layer; mask-position: unset;
One or more <position> values, separated by commas.
Values
<position>-
One to four values representing a 2D position regarding the edges of the element's box. Relative or absolute offsets can be given. Note that the position can be set outside of the element's box.
Formal definition
| Initial value | 0% 0% |
|---|---|
| Applies to | all elements; In SVG, it applies to container elements excluding the <defs> element and all graphics elements |
| Inherited | no |
| Percentages | refer to size of mask painting area minus size of mask layer image (see the text for background-position) |
| Computed value | Consists of two keywords representing the origin and two offsets from that origin, each given as an absolute length (if given a <length>), otherwise as a percentage. |
| Animation type | a repeatable list |
Formal syntax
mask-position =
<position>#
<position> =
[ left | center | right | top | bottom | <length-percentage> ] |
[ left | center | right ] && [ top | center | bottom ] |
[ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] |
[ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ]
<length-percentage> =
<length> |
<percentage>
Examples
Setting mask position
Click "Play" in the live sample to open the code in the MDN Playground and change the mask-position value to any of the allowed values detailed above.
<div id="wrapper"> <div class="masked"></div> </div>
#wrapper {
border: 1px solid black;
width: 250px;
height: 250px;
}
.masked {
width: 250px;
height: 250px;
margin-bottom: 10px;
background: blue linear-gradient(red, blue);
mask-image: url(https://mdn.github.io/shared-assets/images/examples/mask-star.svg);
mask-repeat: no-repeat;
mask-position: top right;
}
Specifications
| Specification |
|---|
| CSS Masking Module Level 1 # the-mask-position |
Browser compatibility
| Desktop | Mobile | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | |
mask-position |
1201 | 1207918–79 | 53 | 10615 | 15.43.1 | 12018 | 53 | 8014 | 15.42 | 25.01.0 | 2 |
See also
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/mask-position