The mask-position
CSS property sets the initial position, relative to the mask position layer set by mask-origin
, for each defined mask image.
/* 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: unset;
Syntax
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 | center
|
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 | repeatable list of simple list of length, percentage, or calc |
Formal syntax
<position>#where <position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]where <length-percentage> = <length> | <percentage>
Examples
Setting mask position
CSS
#wrapper { border: 1px solid black; width: 250px; height: 250px; } #masked { width: 250px; height: 250px; background: blue linear-gradient(red, blue); mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg); mask-repeat: no-repeat; mask-position: top right; /* Can be changed in the live sample */ margin-bottom: 10px; }
HTML
<div id="wrapper">
<div id="masked">
</div>
</div>
<select id="maskPosition">
<option value="top">top</option>
<option value="center">center</option>
<option value="bottom">bottom</option>
<option value="top right" selected>top right</option>
<option value="center center">center center</option>
<option value="bottom left">bottom left</option>
<option value="10px 20px">10px 20px</option>
<option value="60% 20%">60% 20%</option>
</select>
JavaScript
var maskPosition = document.getElementById("maskPosition");
maskPosition.addEventListener("change", function (evt) {
document.getElementById("masked").style.maskPosition = evt.target.value;
});
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Masking Module Level 1The definition of 'mask-position' in that specification. | Candidate Recommendation | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
mask-position
|
Chrome Full support 1 Full support 1 Prefixed' Implemented with the vendor prefix: -webkit- |
Edge
Full support 18 |
Firefox Full support 53 Full support 53 No support 20 — 53 Disabled' From version 20 until version 53 (exclusive): this feature is behind the |
IE
No support No |
Opera Full support 15 Full support 15 Prefixed' Implemented with the vendor prefix: -webkit- |
Safari Full support 3.2 Full support 3.2 Prefixed' Implemented with the vendor prefix: -webkit- |
WebView Android Full support 2 Full support 2 Prefixed' Implemented with the vendor prefix: -webkit- |
Chrome Android Full support 18 Full support 18 Prefixed' Implemented with the vendor prefix: -webkit- |
Firefox Android Full support 53 Full support 53 No support 20 — 53 Disabled' From version 20 until version 53 (exclusive): this feature is behind the |
Opera Android Full support 14 Full support 14 Prefixed' Implemented with the vendor prefix: -webkit- |
Safari iOS Full support 3.2 Full support 3.2 Prefixed' Implemented with the vendor prefix: -webkit- |
Samsung Internet Android Full support 1.0 Full support 1.0 Prefixed' Implemented with the vendor prefix: -webkit- |
Support for three-value syntax of position |
Chrome No support 1 — 68 No support 1 — 68 Prefixed' Implemented with the vendor prefix: -webkit- |
Edge
No support 18 — 79 |
Firefox No support 53 — 70 No support 53 — 70 No support 20 — 53 Disabled' From version 20 until version 53 (exclusive): this feature is behind the |
IE
No support No |
Opera No support 15 — 55 No support 15 — 55 Prefixed' Implemented with the vendor prefix: -webkit- |
Safari Full support 3.2 Full support 3.2 Prefixed' Implemented with the vendor prefix: -webkit- |
WebView Android No support 2 — 68 No support 2 — 68 Prefixed' Implemented with the vendor prefix: -webkit- |
Chrome Android No support 18 — 68 No support 18 — 68 Prefixed' Implemented with the vendor prefix: -webkit- |
Firefox Android Full support 53 Full support 53 No support 20 — 53 Disabled' From version 20 until version 53 (exclusive): this feature is behind the |
Opera Android No support 14 — 48 No support 14 — 48 Prefixed' Implemented with the vendor prefix: -webkit- |
Safari iOS Full support 3.2 Full support 3.2 Prefixed' Implemented with the vendor prefix: -webkit- |
Samsung Internet Android No support 1.0 — 10.0 No support 1.0 — 10.0 Prefixed' Implemented with the vendor prefix: -webkit- |
Legend
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
mask-position by Mozilla Contributors is licensed under CC-BY-SA 2.5.