CSS mask-clip Property
The CSS mask-clip property determines the area of an element that is affected by a CSS mask layer.
It controls the boundaries within which a mask is applied, using areas such as the border box, padding box, or content box. The property can also use SVG-related reference boxes and the no-clip keyword. When multiple mask layers are present, each layer can have its own clipping area.
mask-clip Syntax
The mask-clip property accepts a clipping area keyword or a comma-separated list of values for multiple mask layers.
Basic Syntax
selector {
mask-clip: border-box;
}
Border Box
.element {
mask-clip: border-box;
}
Padding Box
.element {
mask-clip: padding-box;
}
Content Box
.element {
mask-clip: content-box;
}
Border Area
.element {
mask-clip: border-area;
}
No Clipping
.element {
mask-clip: no-clip;
}
SVG Reference Boxes
.element {
mask-clip: fill-box;
}
.element {
mask-clip: stroke-box;
}
.element {
mask-clip: view-box;
}
Multiple Mask Layers
.element {
mask-clip: border-box, content-box;
}
CSS-Wide Keywords
.element {
mask-clip: initial;
}
.element {
mask-clip: inherit;
}
.element {
mask-clip: unset;
}
.element {
mask-clip: revert;
}
.element {
mask-clip: revert-layer;
}
The initial value is border-box, which clips the mask layer to the element's border box.
Property Values
| Value | Description |
|---|---|
border-box |
Clips the mask layer to the element's border box, including the content, padding, and border areas. |
padding-box |
Clips the mask layer to the padding box, excluding the border area. |
content-box |
Clips the mask layer to the content box, excluding the padding and border areas. |
border-area |
Clips the mask to the area occupied by the painted border, accounting for border properties such as style and width. |
fill-box |
Uses the object's fill bounding box as the clipping area. |
stroke-box |
Uses the object's stroke bounding box as the clipping area. |
view-box |
Uses the nearest SVG viewport as the reference box. |
no-clip |
Does not restrict the mask layer to a reference box. |
initial |
Resets the property to border-box. |
inherit |
Inherits the computed value from the parent element. |
unset |
Resets the property to border-box because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | border-box |
| Inherited | No |
| Applies to | All elements, with SVG-specific applicability rules |
| Computed value | As specified |
| Animation type | Discrete |
| Multiple values | Yes, comma-separated values for mask layers |
| Shorthand property | mask |
| Browser availability | Widely available for established values; newer values may have limited support |
How It Works
A CSS mask determines which portions of an element remain visible. The mask-clip property restricts the area where an individual mask layer can contribute to that result.
The element's box model provides the clipping boundaries for values such as border-box, padding-box, and content-box.
The CSS Box Model
+-------------------------------------+
| Border Box |
| +-------------------------------+ |
| | Padding Box | |
| | +-------------------------+ | |
| | | Content Box | | |
| | +-------------------------+ | |
| +-------------------------------+ |
+-------------------------------------+
Step 1: Define the Element
.masked-box {
width: 200px;
padding: 20px;
border: 10px solid #2563eb;
background-color: #059669;
}
The element has separate content, padding, and border areas.
Step 2: Apply a Mask Image
.masked-box {
mask-image: linear-gradient(black, black);
}
The opaque gradient creates a mask layer that would reveal the covered area.
Step 3: Choose the Clipping Area
.masked-box {
mask-image: linear-gradient(black, black);
mask-clip: content-box;
}
The mask layer is restricted to the content box. The padding and border areas are outside the clipping region and are not revealed by this mask layer.
Step 4: Change the Clipping Area
.masked-box {
mask-clip: border-box;
}
The mask layer can now reveal the content, padding, and border areas.
Important Consideration
Mask clipping affects visibility, not layout. The element retains its dimensions, padding, and border measurements even when portions are hidden by the mask.
border-box Value
The border-box value clips the mask layer to the element's border box. This is the initial value.
Basic Example
.element {
mask-clip: border-box;
}
Complete Example
.masked-panel {
padding: 20px;
border: 10px solid #2563eb;
background-color: #059669;
mask-image: linear-gradient(black, black);
mask-clip: border-box;
}
The mask can reveal the element's content, padding, and border areas.
Using a Gradient Mask
.masked-panel {
mask-image: linear-gradient(to right, black, transparent);
mask-clip: border-box;
}
The gradient controls transparency within the border box. Areas beyond the clipping boundary are not revealed by the mask layer.
When to Use border-box
Use border-box when the mask should cover the entire element, including its border.
Important Consideration
The clipping area follows the border box, including its rounded corners where applicable. It does not mean that the mask image itself must be rectangular.
padding-box Value
The padding-box value restricts the mask layer to the content and padding areas, excluding the border.
Basic Example
.element {
mask-clip: padding-box;
}
Complete Example
.masked-panel {
padding: 25px;
border: 12px solid #2563eb;
background-color: #059669;
mask-image: linear-gradient(black, black);
mask-clip: padding-box;
}
The mask reveals the content and padding regions while excluding the border region.
Gradient Mask
.masked-panel {
mask-image: linear-gradient(to bottom, black, transparent);
mask-clip: padding-box;
}
The mask gradient operates within the padding box rather than extending into the border area.
When to Use padding-box
Use padding-box when the mask should include the space surrounding the content but exclude the border.
Important Consideration
Clipping the mask to the padding box does not remove the CSS border declaration. It only prevents this mask layer from revealing the excluded border area.
content-box Value
The content-box value restricts the mask layer to the content area, excluding both padding and border regions.
Basic Example
.element {
mask-clip: content-box;
}
Complete Example
.masked-panel {
padding: 25px;
border: 12px solid #2563eb;
background-color: #059669;
mask-image: linear-gradient(black, black);
mask-clip: content-box;
}
Only the content box is revealed by the opaque mask. The padding and border regions are concealed.
Gradient Mask
.masked-panel {
mask-image: radial-gradient(circle, black 40%, transparent 90%);
mask-clip: content-box;
}
The radial gradient contributes to the mask only within the content box.
When to Use content-box
Use content-box when the mask should be confined to the element's content region, without affecting the surrounding padding and border areas.
Important Consideration
The content box is determined by the CSS box model. Mask clipping does not change the content box's dimensions or the element's normal layout.
border-area Value
The border-area value restricts the mask layer to the area occupied by the element's painted border.
Unlike border-box, which includes the content, padding, and border regions, border-area is intended for masking the border area itself.
Basic Example
.element {
mask-clip: border-area;
}
Complete Example
.masked-border {
padding: 20px;
border: 12px solid #2563eb;
background-color: #059669;
mask-image: linear-gradient(black, black);
mask-clip: border-area;
}
The opaque mask is restricted to the painted border area rather than the entire border box.
Gradient Border Mask
.masked-border {
border: 15px solid transparent;
mask-image: linear-gradient(135deg, black, transparent);
mask-clip: border-area;
}
The mask is clipped according to the painted border geometry. Border color transparency does not by itself remove that area from the clipping region.
Difference from border-box
| Value | Clipping Area |
|---|---|
border-box |
Content, padding, and border areas |
border-area |
Area occupied by the painted border |
Important Consideration
The border-area value is a newer feature and may not be supported in all browsers. Check compatibility before relying on it for an essential effect.
SVG Reference Boxes
The fill-box, stroke-box, and view-box values provide reference boxes commonly used with SVG elements.
fill-box
.shape {
mask-clip: fill-box;
}
The mask layer is clipped to the object's fill bounding box.
stroke-box
.shape {
mask-clip: stroke-box;
}
The mask layer is clipped to the object's stroke bounding box, which accounts for its stroke geometry.
view-box
.shape {
mask-clip: view-box;
}
The mask layer is clipped using the nearest SVG viewport as its reference box.
SVG Example
<svg viewBox="0 0 200 120" xmlns="http://www.w3.org/2000/svg">
<rect class="masked-shape" x="30" y="20" width="140" height="80" rx="15" fill="#2563eb" stroke="#059669" stroke-width="12"/>
</svg>
CSS Example
.masked-shape {
mask-image: linear-gradient(to right, black, transparent);
mask-clip: stroke-box;
}
The mask uses the SVG rectangle's stroke bounding box as its clipping reference.
Using SVG Values on HTML Elements
For ordinary HTML elements, fill-box generally corresponds to content-box, while stroke-box and view-box generally correspond to border-box.
Important Consideration
SVG reference boxes are useful when masking vector graphics. Their behavior depends on the element's geometry and the applicable SVG viewport or bounding box.
no-clip Value
The no-clip keyword prevents the mask layer from being clipped to a particular reference box.
Basic Example
.element {
mask-clip: no-clip;
}
Complete Example
.masked-panel {
mask-image: radial-gradient(circle, black 50%, transparent 80%);
mask-size: 150% 150%;
mask-position: center;
mask-repeat: no-repeat;
mask-clip: no-clip;
}
The mask layer is not restricted to the border, padding, or content box by mask-clip.
Compare with border-box
.clipped {
mask-clip: border-box;
}
.unclipped {
mask-clip: no-clip;
}
The first mask layer is restricted to the border box. The second has no clipping restriction from this property.
When to Use no-clip
Use no-clip when a mask layer needs to extend beyond the element's normal box boundaries.
Important Consideration
The no-clip value does not disable the mask itself. It also does not override unrelated clipping mechanisms, such as an ancestor's overflow: hidden or a separate clip-path.
Multiple Mask Layers
The mask-clip property supports comma-separated values when an element has multiple mask image layers.
Two Mask Layers
.element {
mask-image:
linear-gradient(black, black),
radial-gradient(circle, black, transparent);
mask-clip: border-box, content-box;
}
The first mask layer uses border-box. The second uses content-box.
Three Mask Layers
.element {
mask-image:
linear-gradient(black, transparent),
radial-gradient(circle, black, transparent),
linear-gradient(white, white);
mask-clip: border-box, padding-box, content-box;
}
Each mask layer uses its corresponding clipping area.
Fewer Values Than Layers
.element {
mask-image:
linear-gradient(black, transparent),
radial-gradient(circle, black, transparent),
linear-gradient(white, white);
mask-clip: border-box, content-box;
}
When there are more mask layers than clipping values, the values repeat. The third layer uses border-box.
More Values Than Layers
.element {
mask-image: linear-gradient(black, transparent);
mask-clip: border-box, padding-box, content-box;
}
Only the first clipping value is used because there is one mask image layer.
Combining Mask Layers
Multiple mask layers are combined according to the mask-composite property. Their clipping regions affect the mask data available for that combination.
Important Consideration
Each mask-clip value corresponds to a mask layer, not a side of the element. Commas separate layers rather than top, right, bottom, and left values.
mask-origin vs. mask-clip
The mask-origin and mask-clip properties control different aspects of mask placement.
| Property | Purpose |
|---|---|
mask-origin |
Determines the positioning area used to place the mask image. |
mask-clip |
Determines the area within which the mask layer can affect visibility. |
mask-size |
Controls the dimensions of the mask image. |
mask-position |
Controls the position of the mask image within its positioning area. |
Different Origin and Clip Areas
.element {
mask-image: linear-gradient(black, transparent);
mask-origin: border-box;
mask-clip: content-box;
}
The mask image is positioned relative to the border box but clipped to the content box.
Matching Origin and Clip Areas
.element {
mask-image: linear-gradient(black, transparent);
mask-origin: padding-box;
mask-clip: padding-box;
}
The mask is positioned and clipped using the padding box.
Changing Only the Clipping Area
.element {
mask-origin: border-box;
mask-clip: content-box;
}
Changing the clipping area does not automatically change the mask image's positioning area.
Important Consideration
Use mask-origin to control where the mask image is positioned and mask-clip to control where that mask layer can contribute to visibility.
Using the mask Shorthand
The mask-clip property is a longhand component of the mask shorthand.
Shorthand Example
.element {
mask: linear-gradient(black, transparent) center / cover no-repeat border-box content-box;
}
The border-box value sets mask-origin, while content-box sets mask-clip.
Equivalent Longhand Declarations
.element {
mask-image: linear-gradient(black, transparent);
mask-position: center;
mask-size: cover;
mask-repeat: no-repeat;
mask-origin: border-box;
mask-clip: content-box;
}
One Box Value in the Shorthand
.element {
mask: linear-gradient(black, transparent) padding-box;
}
When a single geometry box value is specified, it sets both mask-origin and mask-clip.
Using no-clip
.element {
mask: linear-gradient(black, transparent) border-box no-clip;
}
The mask image is positioned relative to the border box without clipping it to that box.
Override the Shorthand
.element {
mask: linear-gradient(black, transparent) border-box;
mask-clip: content-box;
}
The later longhand declaration changes the clipping area to content-box.
Shorthand Reset Behavior
.element {
mask-clip: content-box;
mask: linear-gradient(black, transparent);
}
The later shorthand resets mask-clip to its initial value of border-box because no clipping value is specified.
Correct Declaration Order
.element {
mask: linear-gradient(black, transparent);
mask-clip: content-box;
}
Place the longhand declaration after the shorthand when it should override the shorthand's default clipping behavior.
mask-clip Example
This example demonstrates how border-box, padding-box, and content-box change the visible area of an element.
Each box has the same dimensions, padding, border, and opaque mask image. Only the mask-clip value changes.
HTML Example
<div class="mask-clip-demo">
<div class="mask-clip-item">
<div class="mask-clip-box clip-border">Border Box</div>
<p>border-box</p>
</div>
<div class="mask-clip-item">
<div class="mask-clip-box clip-padding">Padding Box</div>
<p>padding-box</p>
</div>
<div class="mask-clip-item">
<div class="mask-clip-box clip-content">Content Box</div>
<p>content-box</p>
</div>
</div>
CSS Example
.mask-clip-demo {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.mask-clip-item {
text-align: center;
}
.mask-clip-box {
display: flex;
align-items: center;
justify-content: center;
min-height: 110px;
padding: 20px;
border: 12px solid #2563eb;
background-color: #059669;
color: #fff;
font-weight: bold;
text-align: center;
mask-image: linear-gradient(black, black);
mask-origin: border-box;
}
.clip-border {
mask-clip: border-box;
}
.clip-padding {
mask-clip: padding-box;
}
.clip-content {
mask-clip: content-box;
}
.mask-clip-item p {
margin: 12px 0 0;
font-weight: bold;
}
@media (max-width: 575px) {
.mask-clip-demo {
grid-template-columns: 1fr;
}
}
border-box
padding-box
content-box
The first example reveals the border, padding, and content areas. The second excludes the border. The third reveals only the content area.
The elements retain their original layout dimensions even when their border and padding regions become transparent.
Using a Gradient Mask
.masked-panel {
padding: 20px;
border: 10px solid #2563eb;
mask-image: linear-gradient(to right, black, transparent);
mask-clip: padding-box;
}
The gradient fades the element within the padding box while excluding the border area.
Clipping to the Content Box
.masked-panel {
mask-image: radial-gradient(circle, black 50%, transparent 90%);
mask-clip: content-box;
}
The radial gradient contributes to the mask only within the content box.
Removing the Clipping Boundary
.masked-panel {
mask-image: radial-gradient(circle, black 50%, transparent 90%);
mask-size: 150% 150%;
mask-position: center;
mask-repeat: no-repeat;
mask-clip: no-clip;
}
The mask layer can extend beyond the usual box clipping boundary, subject to other clipping and rendering constraints.
Common Mistakes
Confusing mask-clip with clip-path
The mask-clip property determines the clipping area of a mask layer. The clip-path property defines a clipping region using shapes, paths, or other supported geometry.
Confusing mask-clip with mask-origin
The mask-origin property controls mask image positioning. The mask-clip property controls the area where the mask layer can affect visibility.
Using Invalid Length Values
.element {
mask-clip: 20px;
}
The property does not accept lengths. Use a supported clipping keyword.
Using Invalid Percentage Values
.element {
mask-clip: 50%;
}
Percentages are not valid mask-clip values.
Expecting content-box to Remove Padding
The content-box value can conceal the padding region through masking, but the element still retains its CSS padding and layout dimensions.
Expecting no-clip to Disable Masking
The no-clip value removes the mask layer's reference-box clipping restriction. It does not remove the mask image or make the element fully visible.
Using Space-Separated Values for Multiple Layers
.element {
mask-clip: border-box content-box;
}
Separate mask layer values with commas. The space-separated declaration above is not a valid mask-clip value.
Forgetting the Mask Image
The mask-clip property does not create a mask by itself. A mask layer must be supplied through mask-image or the mask shorthand.
Overwriting the Value with a Shorthand
.element {
mask-clip: content-box;
mask: linear-gradient(black, transparent);
}
The later shorthand resets the clipping area to border-box.
Assuming Every Value Has Identical Browser Support
Support for established box values is broader than support for newer values such as border-area. Check compatibility for the specific value being used.
Important Considerations
Keep the following points in mind when using mask-clip:
- The property determines the clipping area of a CSS mask layer.
- Its initial value is
border-box. - The property is not inherited.
- The
border-boxvalue includes the content, padding, and border regions. - The
padding-boxvalue excludes the border region. - The
content-boxvalue excludes the padding and border regions. - The
border-areavalue uses the painted border geometry. - The
fill-boxvalue uses the object's fill bounding box. - The
stroke-boxvalue uses the object's stroke bounding box. - The
view-boxvalue uses an SVG viewport reference box. - The
no-clipvalue removes the reference-box clipping restriction for the mask layer. - The property accepts keywords rather than lengths or percentages.
- Multiple mask layers can use different clipping areas.
- Comma-separated values correspond to mask layers.
- When fewer clipping values are supplied than mask layers, the values repeat.
- The property does not determine the mask image's position.
- The
mask-originproperty determines the positioning area. - The
mask-sizeproperty controls the mask image dimensions. - The
mask-positionproperty controls the mask image position. - The
mask-compositeproperty controls how multiple mask layers are combined. - Mask clipping affects visibility rather than document layout.
- Clipped regions can become transparent without changing the element's box dimensions.
- The property is a longhand component of the
maskshorthand. - The shorthand resets omitted clipping values to
border-box. - Some SVG-related values have different reference-box behavior on SVG and HTML elements.
- Browser support varies by value, particularly for newer features.
- Test masking effects in the browsers your website supports.
Browser Support
The CSS mask-clip property is widely available in modern browsers as part of CSS masking. Support for individual values can vary, particularly for newer features such as border-area.
The commonly used border-box, padding-box, and content-box values are suitable for many modern browser implementations. SVG-related values and newer clipping options should be tested separately.
For current compatibility information, visit Can I Use? and search for mask-clip.
For older browser support, verify whether a prefixed implementation is required. Do not assume that every standardized clipping value is supported by a legacy prefixed property.
Specifications
The mask-clip property is defined in CSS Masking Module Level 1, with newer values described in subsequent CSS masking specifications.
CSS Masking Module Level 1: mask-clip
The specification defines mask clipping areas, reference boxes, and how mask layers are restricted to those regions.
For additional documentation and examples, consult MDN Web Docs.
