The mask-origin property

The mask-origin property sets the reference point for mask positioning. It determines which part of the element (border, padding, or content) the mask will be positioned relative to.

Syntax

cssselector {
  mask-origin: content-box | padding-box | border-box;
}

Values

Value Description
border-box The mask is positioned relative to the element's border (including border).
padding-box The mask is positioned relative to the padding area (default).
content-box The mask is positioned relative to the element's content.

Example . border-box

Mask positioned relative to the element's border:

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  padding: 20px;
  border: 30px dashed rgba(0,0,0,0.3);
  mask-image: url("heart.svg");
  mask-position: center;
  mask-size: 200px;
  mask-repeat: no-repeat;
  mask-origin: border-box;
}

Результат:

Example . padding-box

Mask positioned relative to the padding area:

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  padding: 20px;
  border: 30px dashed rgba(0,0,0,0.3);
  mask-image: url("heart.svg");
  mask-position: center;
  mask-size: 200px;
  mask-repeat: no-repeat;
  mask-origin: padding-box;
}

Результат:

Example . content-box

Mask positioned relative to the content:

html<img id="image" src="image.jpg">
css#image {
  width: 500px;
  height: 281px;
  padding: 20px;
  border: 30px dashed rgba(0,0,0,0.3);
  mask-image: url("heart.svg");
  mask-position: center;
  mask-size: 200px;
  mask-repeat: no-repeat;
  mask-origin: content-box;
}

Результат:

See also

  • property mask-clip,
    defines the mask clipping area
  • property mask-position,
    sets the mask position
  • property mask,
    shorthand for all masking properties
  • property background-origin,
    similar property for element background