The mask-origin
CSS property sets the origin of a mask.
/* Keyword values */ mask-origin: content-box; mask-origin: padding-box; mask-origin: border-box; mask-origin: margin-box; mask-origin: fill-box; mask-origin: stroke-box; mask-origin: view-box; /* Multiple values */ mask-origin: padding-box, content-box; mask-origin: view-box, fill-box, border-box; /* Non-standard keyword values */ -webkit-mask-origin: content; -webkit-mask-origin: padding; -webkit-mask-origin: border; /* Global values */ mask-origin: inherit; mask-origin: initial; mask-origin: unset;
For elements rendered as a single box, this property specifies the mask positioning area. In other words, this property specifies the origin position of an image specified by the mask-image
CSS property. For elements rendered as multiple boxes, such as inline boxes on several lines or boxes on several pages, it specifies which boxes box-decoration-break
operates upon to determine the mask positioning area.
Syntax
One or more of the keyword values listed below, separated by commas.
Values
content-box
- The position is relative to the content box.
padding-box
- The position is relative to the padding box. For single boxes
0 0
is the upper left corner of the padding edge,100% 100%
is the lower right corner. border-box
- The position is relative to the border box.
margin-box
- The position is relative to the margin box.
fill-box
- The position is relative to the object bounding box.
stroke-box
- The position is relative to the stroke bounding box.
view-box
- Uses the nearest SVG viewport as reference box. If a
viewBox
attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by theviewBox
attribute and the dimension of the reference box is set to the width and height values of theviewBox
attribute. content
'- Same as
content-box
. padding
'- Same as
padding-box
. border
'- Same as
border-box
.
Formal definition
Initial value | border-box
|
Applies to | all elements; In SVG, it applies to container elements excluding the defs element and all graphics elements
|
Inherited | no |
Computed value | as specified |
Animation type | discrete |
Formal syntax
<geometry-box>#where <geometry-box> = <shape-box> | fill-box | stroke-box | view-boxwhere <shape-box> = <box> | margin-boxwhere <box> = border-box | padding-box | content-box
Examples
Setting mask origin to border-box
CSS
#masked { width: 100px; height: 100px; margin: 10px; border: 10px solid blue; background-color: #8cffa0; padding: 10px; mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg); mask-origin: border-box; /* Can be changed in the live sample */ }
HTML
<div id="masked">
</div>
<select id="origin">
<option value="content-box">content-box</option>
<option value="padding-box">padding-box</option>
<option value="border-box" selected>border-box</option>
<option value="margin-box">margin-box</option>
<option value="fill-box">fill-box</option>
<option value="stroke-box">stroke-box</option>
<option value="view-box">view-box</option>
</select>
JavaScript
var origin = document.getElementById("origin");
origin.addEventListener("change", function (evt) {
document.getElementById("masked").style.maskOrigin = evt.target.value;
});
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Masking Module Level 1The definition of 'mask-origin' 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-origin
|
Chrome Full support 1 Full support 1 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
Edge Full support 79 Full support 79 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
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-
Notes' The |
Safari Full support 4 Full support 4 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
WebView Android Full support 2 Full support 2 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
Chrome Android Full support 18 Full support 18 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
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-
Notes' The |
Safari iOS Full support 3.2 Full support 3.2 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
Samsung Internet Android Full support 1.0 Full support 1.0 Prefixed' Implemented with the vendor prefix: -webkit-
Notes' The |
fill-box
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
Non-standard values |
Chrome Full support 1 Full support 1 Prefixed' Implemented with the vendor prefix: -webkit- |
Edge Full support 79 Full support 79 Prefixed' Implemented with the vendor prefix: -webkit- |
Firefox
No support No |
IE
No support No |
Opera Full support 15 Full support 15 Prefixed' Implemented with the vendor prefix: -webkit- |
Safari Full support 4 Full support 4 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
No support No |
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- |
stroke-box
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
view-box
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
Legend
- Full support
- Full support
- No support
- No support
- Non-standard. Expect poor cross-browser support.'
- Non-standard. Expect poor cross-browser support.
- See implementation notes.'
- See implementation notes.
- 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-origin by Mozilla Contributors is licensed under CC-BY-SA 2.5.