W3cubDocs

/CSS

mask-position

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;
}

Result

Specifications

Specification Status Comment
CSS Masking Module Level 1
The definition of 'mask-position' in that specification.
Candidate Recommendation Initial definition

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
mask-position 1
Prefixed
1
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
18 53
53
20 — 53
Disabled
Disabled From version 20 until version 53 (exclusive): this feature is behind the layout.css.masking.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 15
Prefixed
15
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
3.2
Prefixed
3.2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support for three-value syntax of position 1 — 68
Prefixed
1 — 68
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
18 — 79 53 — 70
53 — 70
20 — 53
Disabled
Disabled From version 20 until version 53 (exclusive): this feature is behind the layout.css.masking.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 15 — 55
Prefixed
15 — 55
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
3.2
Prefixed
3.2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
mask-position 2
Prefixed
2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
18
Prefixed
18
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
53
53
20 — 53
Disabled
Disabled From version 20 until version 53 (exclusive): this feature is behind the layout.css.masking.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
14
Prefixed
14
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
3.2
Prefixed
3.2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
1.0
Prefixed
1.0
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Support for three-value syntax of position 2 — 68
Prefixed
2 — 68
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
18 — 68
Prefixed
18 — 68
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
53
53
20 — 53
Disabled
Disabled From version 20 until version 53 (exclusive): this feature is behind the layout.css.masking.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
14 — 48
Prefixed
14 — 48
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
3.2
Prefixed
3.2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
1.0 — 10.0
Prefixed
1.0 — 10.0
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-

© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/mask-position