Mask-clip - CSS Property

mask-clip

Summary of characteristics of the mask-clip property

Quick description
Defines the area to be masked.
Status
Standard
Applies to
HTML: all elements.
SVG: containers except defs, graphic elements, use.
Predefined values
border-box | padding-box | content-box | fill-box | stroke-box | view-box | no-clip | text
Percentages
Not applicable.
Initial value
border-box
Inherited by default
No.
Discrète: during an animation, the mask-clip property passes from one value to another without transition.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Masking Module
Document status: CR (Candidate Recommendation)

Syntax diagram of mask-clip.

Mask-clip property - Syntax diagramSyntax diagram of the mask-clip CSS property. See stylescss.free.fr for details. content-box content-box padding-box padding-box border-box border-box fill-box fill-box stroke-box stroke-box viex-box viex-box no-clip no-clip , ,mask-clip:;mask-clip:;
Syntax diagram of the mask-clip property.
The links in the diagram provide more details about the values.
Download the diagram.

Description of the mask-clip property.

Masking involves making two elements interact with each other. One of them, called the mask, hides certain parts of the other. Masking is proportional to the mask's alpha channel. So it is possible to use masks with semi-transparent areas.

The property mask-clip defines the area of the element that will be affected by the mask. Parts of the element outside this area won't be displayed. mask-clip has no effect if no mask is applied to the element (see mask-image or mask ).

For mask-clip to be operational, the mask must be a PNG file or a gradient, but not a SVG file. For masks written in SVG, you'll need to use the attributes of the mask tag: x, y, width, height, and maskUnits. It's less convenient than CSS.

Here's an example. The element below has a 10-pixel border and 20 pixels of padding (padding). A mask is applied to it, creating this pointillism effect. Here's what will be visible depending on the value assigned to mask-clip. The parts not covered by the mask are not displayed.

Block content
The original element, without masking.
Block content
border-box
The element is fully visible, with its border and inner margins.

Block content
padding-box
The inner margins are visible, but not the border.

Block content
content-box
The border and the inner margins are hidden.

For more complete explanations on masking, refer to the shortcut property mask .

Values for mask-clip.

  • mask-clip: border-box;

    With the border-box value, the content, padding, and border of the element are affected by the mask. It's the default value.

    Content
    mask-clip:border-box;
  • mask-clip: padding-box;

    The content and inner padding of the element are affected by the mask, but not the border.

    Content
    mask-clip:padding-box;
  • mask-clip: content-box;

    Only the content of the element is affected by masking, excluding its inner padding (padding) and border.

    Content
    mask-clip:content-box;
  • mask-clip: no-clip;

    The no-clip value doesn't change anything about the mask's area: no cutting is done.

    Content
    mask-clip:no-clip;
  • mask-clip: fill-box; mask-clip: stroke-box; mask-clip: view-box;

    These three values apply to SVG-type elements. In HTML, we have the following equivalents:

    • fill-box is equivalent tocontent-box.
    • stroke-box is equivalent to border-box.
    • view-box has no equivalent. It behaves like border-box or no-clip.
    Content

    clip-mask:fill-box;
    Content

    clip-mask:stroke-box;
    Content

    clip-mask:view-box;
  • mask-clip: text; ⚠

    The area where the mask applies is limited to the shape of the element's text. Not all browsers recognize this value.

    Content
    mask-clip:text;
  • mask-clip: border-box, content-box;

    When several are indicated, separated by commas, mask-clip assigns each of the values to a mask. See the mask property for more information on masques multiples.

    The example below has two masks. The first one, a color gradient, gets the value border-box. The border is actually partially masked at the bottom. The second one is a PNG image (a grid pattern) that only applies to padding-box: the border isn’t affected.

    Content
    mask-clip:border-box,padding-box;
  • mask-clip: initial; (border-box) mask-clip: inherit; mask-clip: revert; mask-clip: revert-layer; mask-clip: revert-rule; mask-clip: unset;

    These values ​​are described in more detail on their respective page: initial, inherit, revert, revert-layer, revert-rule, unset.

Animation of the mask-clip property.

Here's an example of an animation for the mask-clip property, which results in a blinking border.

Access the mask-clip property via a program

With Javascript, read the value of mask-clip.

Here are two examples of Javascript code to change the value of the mask-clip property. Javascript allows a syntax with the typical CSS notation, in kebab-case, and another syntax with the camel-case notation, which is more common in Javascript.

Javascript
let el = document.getElementById('id'); el.style['mask-clip'] = 'content-box'; // or let el = document.getElementById('id'); el.style.maskClip = 'content-box';

With Javascript, change the value of mask-clip.

This code gets the value of the mask-clip property if it has been assigned directly to the element itself in the HTML code, using the style attribute and not through CSS with a selector. So it's basically the mirror of the previous code.

Javascript
let el = document.getElementById('id'); let value = el.style['mask-clip']; // or let el = document.getElementById('id'); let value = el.style.maskClip;

With Javascript, read the computed value of mask-clip.

The computed value is the one that has been assigned to the element via any selector, or failing that, the one obtained through the inheritance mechanism. If the value hasn't been assigned anywhere, it will be the initial value: border-box.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('mask-clip');

With JQuery, read or change the value of mask-clip.

Like in JavaScript, writing in kebab-case and camel-case is accepted.

JQuery

// Read the value:
$('#id').prop('mask-clip');
// Write the value:
$('#id').prop('mask-clip', 'content-box');
$('#id').prop('{mask-clip': 'content-box'});

With JQuery, read the computed value of mask-clip.

JQuery
let value = $('#id').css('mask-clip');

Other code examples.

Go check out other examples of JavaScript and JQuery code on the page Javascript and CSS.

Test it yourself.

The buttons below apply the entered value to the mask-clip property and then display either the value as it was applied or the computed value, which, in the case of mask-clip, won't make a difference since the property only accepts predefined values.

Simulator.

The demo block below has 20-pixel margins, a 10-pixel border, 20 pixels of padding, and a blue background. This helps visualize the parts that are visible and those that are hidden depending on the value given to mask-clip.

mask-clip :
This block has margins of 20 pixels, a border of 10 pixels, and an inner padding of 20 pixels.

Browsers compatibility with mask-clip.

The property mask-clip is well recognized by all recent browsers.

Column 1
Support for masking techniques consisting of masking an element with an image or a geometric shape.
Column 2
Support for the property mask-clip which defines how far the mask extends.

Notes:

(1) Requires the -webkit- prefix. Supports the properties mask-image and >mask-box-image but not the other mask-related properties.

1
Using an image
as a mask
2
mask-clip
property
Estimated overall support.
97%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Safari

Safari sur IOS

Chrome

Opéra

Edge

Chrome pour Androïd

Firefox pour Androïd

Firefox

Androïd Brower

KaiOS Browser

Opéra mini

Historic of the mask-clip property.

  • CSS Masking Module Level 1

    This specification module describes two ways to partially or completely hide portions of visual elements: masking and clipping.
    Masking involves using another graphic element or an image as a mask.
    Clipping describes the visible region of visual elements. The region can be described using certain SVG graphic elements or simple shapes. Anything outside this region is not rendered.

    Regarding mask-clip Introduction of image masking techniques. And initial definition of the mask-clip property.
    WD
    November 15, 2012
    Working Draft.
    CR
    August 26, 2014
    Candidate Recommendation.
    PR
    REC

See also, about masking techniques.

The property mask-clip is defined in the specification that standardizes everything related to masking, which is called CSS Masking Module. The following properties are also presented in this module:

Properties:

✗
clip
Langue française
Cuts an element from a rectangle.
clip-path
Defines the visible part of the element, delimited by a geometric shape (rectangle, polygon, etc.).
clip-rule
Defines how to handle hollow shapes in the context of a clipping.
mask
Langue française
A shorthand property that defines the masking parameters: mask dimensions, position, repeat, origin, etc.
mask-border
Short-hand property. Sets all the parameters of a mask for the edges of an element.
⚠
mask-border-mode
Defines according to which parameter the mask should act (luminance, alpha).
⚠
mask-border-outset
Sets the possible offset of the edge mask relative to the element.
⚠
mask-border-repeat
Sets the repeat mode of the mask for the edges of the element.
⚠
mask-border-slice
Defines how the image used as a mask should be partitioned.
⚠
mask-border-source
Specifies the image that will be used as a mask for the edges of the element.
⚠
mask-border-width
Sets the thickness over which the edge mask operates.
Mask-clip
Defines the area to be masked.
mask-composite
Defines how masks will be combined when multiple are applied to an element.
mask-image
Specifies the image or SVG file that will be used as a mask.
mask-mode
Langue française
Sets the masking mode (alpha channel, luminance...)
mask-origin
Langue française
Sets the reference for the positioning of the mask.
mask-position
Langue française
Defines the position of the mask.
mask-position-x
Langue française
Defines the horizontal position of the mask.
mask-position-y
Langue française
Defines the vertical position of the mask.
mask-repeat
Langue française
Sets how the mask repeats when the mask is smaller than the element to be masked.
mask-size
Langue française
Fixe les dimensions du masque.
mask-type
Langue française
Defines which mask parameter is used to hide the element.