CSS mask-border-slice Property

The CSS mask-border-slice property divides a mask border source image into nine regions that can be used to mask an element's corners, edges, and center.

It accepts one to four nonnegative numbers or percentages to position the slicing lines. The optional fill keyword determines whether the center region is included in the mask. This property works with mask-border-source, mask-border-width, and mask-border-repeat to create image-based masking effects.

mask-border-slice Syntax

The mask-border-slice property accepts one to four nonnegative numbers or percentages, optionally combined with the fill keyword.

Basic Syntax

selector {
  mask-border-slice: 30;
}

Number Value

.element {
  mask-border-slice: 25;
}

Percentage Value

.element {
  mask-border-slice: 25%;
}

Multiple Values

.element {
  mask-border-slice: 10 20 30 40;
}

Include the Center Region

.element {
  mask-border-slice: 30 fill;
}

Percentage Values with fill

.element {
  mask-border-slice: 20% 30% fill;
}

CSS-Wide Keywords

.element {
  mask-border-slice: initial;
}
.element {
  mask-border-slice: inherit;
}
.element {
  mask-border-slice: unset;
}
.element {
  mask-border-slice: revert;
}
.element {
  mask-border-slice: revert-layer;
}

The initial value is 0, which places the slicing lines at the source image's edges.

Property Values

Value Description
<number> Specifies a nonnegative slicing offset in source image coordinates for raster images, or in the SVG viewBox coordinate system for SVG images.
<percentage> Specifies a slicing offset relative to the source image's width or height.
fill Preserves the center image region for use in the mask.
initial Resets the property to its initial value of 0.
inherit Inherits the computed value from the parent element.
unset Resets the property to 0 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 0
Inherited No
Applies to All elements, with SVG-specific applicability rules
Computed value Numbers and percentages as specified, with the fill keyword retained when present
Animation type By computed value type
Accepted numeric values One to four nonnegative numbers or percentages
Length values Not permitted
Optional keyword fill
Shorthand property mask-border
Browser availability Limited availability

How It Works

The mask-border-slice property divides the source image using four slicing lines. These lines create nine rectangular regions.

The browser uses the corner and edge regions to construct the mask border. The center region is included only when the fill keyword is specified.

Nine-Slice Image

+--------------+--------------+--------------+
|   Top Left   |   Top Edge   |   Top Right  |
+--------------+--------------+--------------+
|   Left Edge  |    Center    |  Right Edge  |
+--------------+--------------+--------------+
|  Bottom Left |  Bottom Edge | Bottom Right |
+--------------+--------------+--------------+

Corner Regions

The four corner regions are placed at the corresponding corners of the mask border area.

Edge Regions

The top, right, bottom, and left regions are stretched or repeated according to mask-border-repeat.

Center Region

The center region is discarded unless fill is specified. When included, it contributes to the mask covering the element's center.

Slicing Lines

.element {
  mask-border-slice: 20 30 40 50;
}

The slicing lines are positioned 20 units from the top, 30 from the right, 40 from the bottom, and 50 from the left of the source image.

Source Image Dimensions

Slicing values are measured against the source image, not the element's border box. The sliced regions are subsequently positioned and scaled to fit the mask border area.

Important Consideration

Changing the slicing values changes which parts of the source image are used for corners, edges, and the center. It does not change the original image file.

Number Values

Unitless numbers specify slicing offsets in the source image's coordinate system.

Raster Image Example

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30;
}

For a raster image, the slicing lines are positioned 30 image pixels inward from the corresponding edges.

Different Slicing Offsets

.element {
  mask-border-slice: 10 20 30 40;
}

Each side uses a different source image offset.

Fractional Numbers

.element {
  mask-border-slice: 12.5;
}

Nonnegative fractional values are permitted.

SVG Source Images

.element {
  mask-border-source: url("border-mask.svg");
  mask-border-slice: 20;
}

For SVG images, unitless numbers refer to the source image's coordinate system, such as its viewBox dimensions, rather than necessarily representing physical pixels.

Zero Values

.element {
  mask-border-slice: 0;
}

A zero value places the slicing lines at the corresponding image edges, leaving the center region to occupy the source image area.

Important Consideration

Do not append px to a number value. The slicing syntax accepts unitless numbers or percentages, not CSS length units.

Percentage Values

Percentage values position slicing lines relative to the dimensions of the source image.

Basic Percentage Example

.element {
  mask-border-slice: 25%;
}

The slicing lines are positioned one-quarter of the source image's width or height inward from the corresponding edges.

Different Percentages

.element {
  mask-border-slice: 10% 20% 30% 40%;
}

The top and bottom percentages are calculated from the source image's height. The left and right percentages are calculated from its width.

Example with a 200 by 100 Image

Suppose a source image is 200 pixels wide and 100 pixels high.

.element {
  mask-border-slice: 20%;
}

The top and bottom offsets are 20 pixels each, while the left and right offsets are 40 pixels each.

Percentage Values with fill

.element {
  mask-border-slice: 20% fill;
}

The source image is sliced 20% inward from each edge, and the center region is included in the mask.

Mixed Numbers and Percentages

.element {
  mask-border-slice: 20 15% 30 10%;
}

Numbers and percentages can be combined in the same declaration.

Important Consideration

Percentages are based on the source image dimensions, not the width or height of the HTML element receiving the mask.

One to Four Values

The mask-border-slice property uses the familiar CSS clockwise side order.

One Value

.element {
  mask-border-slice: 30;
}

All four slicing offsets use the value 30.

Two Values

.element {
  mask-border-slice: 20 40;
}

The top and bottom use 20. The right and left use 40.

Three Values

.element {
  mask-border-slice: 10 20 30;
}

The top uses 10, the right and left use 20, and the bottom uses 30.

Four Values

.element {
  mask-border-slice: 10 20 30 40;
}

The values apply to the top, right, bottom, and left, respectively.

Value Order Reference

Number of Values How Values Are Applied
One All four sides
Two Top and bottom | Right and left
Three Top | Right and left | Bottom
Four Top | Right | Bottom | Left

Mixed Value Types

.element {
  mask-border-slice: 15% 20 25% 30;
}

Each offset is interpreted independently according to whether it is a percentage or a number.

Important Consideration

Values are measured inward from the source image edges. They are not measurements of the mask border's rendered width.

The fill Keyword

The fill keyword preserves the center region of the sliced source image so it can contribute to the element's mask.

Without fill

.element {
  mask-border-slice: 30;
}

The center region of the source image is discarded. Only the corner and edge regions contribute to the mask border.

With fill

.element {
  mask-border-slice: 30 fill;
}

The center region is retained and used to mask the center of the element.

fill Before the Slicing Values

.element {
  mask-border-slice: fill 30;
}

The fill keyword can appear before or after the slicing values.

Percentage Slicing with fill

.element {
  mask-border-slice: 20% fill;
}

Different Side Offsets with fill

.element {
  mask-border-slice: 10 20 30 40 fill;
}

Why fill Matters

A mask border source may contain opaque regions around its edges and a separate center design. Without fill, the center design is discarded during slicing.

When fill is present, the center can reveal or conceal the element according to the source image's mask values and the selected mask-border-mode.

Important Consideration

The fill keyword does not automatically make the center fully visible. The actual transparency of the center depends on the source image and masking mode.

Slice vs. Width

The mask-border-slice and mask-border-width properties serve different purposes.

Property Purpose
mask-border-slice Determines where the source image is divided into corners, edges, and a center.
mask-border-width Determines the widths of the regions where the sliced mask border image is rendered.
mask-border-outset Determines how far the mask border area extends beyond the element's border box.

Slicing the Source Image

.element {
  mask-border-slice: 30 fill;
}

This divides the source image using offsets of 30 and preserves its center region.

Setting the Rendered Border Width

.element {
  mask-border-width: 20px;
}

This sets the widths of the rendered mask border regions to 20 pixels.

Using Both Properties

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
}

The source image is sliced at the specified offsets, and its corner and edge regions are rendered using the specified mask border widths.

Adding an Outset

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-outset: 10px;
}

The mask border area extends 10 pixels beyond the border box without changing the source image slicing offsets.

Important Consideration

A slice value of 30 does not mean the rendered mask border will be 30 pixels wide. Source image slicing and rendered border sizing are separate operations.

Using the mask-border Shorthand

The mask-border-slice property is one of six longhand properties represented by the mask-border shorthand.

Shorthand Example

.element {
  mask-border: url("border-mask.png") 30 fill / 20px / 5px round alpha;
}

The 30 fill portion specifies the slicing offsets and preserves the center region.

Equivalent Longhand Declarations

.element {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
  mask-border-outset: 5px;
  mask-border-repeat: round;
  mask-border-mode: alpha;
}

Percentage Slicing in the Shorthand

.element {
  mask-border: url("border-mask.png") 25% fill / 15px round;
}

Different Slicing Offsets

.element {
  mask-border: url("border-mask.png") 10 20 30 40 fill / 20px stretch;
}

Override the Shorthand

.element {
  mask-border: url("border-mask.png") 30 fill / 20px round;
  mask-border-slice: 20 fill;
}

The later longhand declaration changes the slicing offsets to 20.

Shorthand Reset Behavior

.element {
  mask-border-slice: 30 fill;
  mask-border: url("border-mask.png");
}

The later shorthand resets mask-border-slice to its initial value of 0 because no slicing value is included.

Interaction with mask

.element {
  mask-border-slice: 30 fill;
  mask: linear-gradient(black, transparent);
}

The mask shorthand resets mask border properties, including mask-border-slice.

Correct Declaration Order

.element {
  mask: linear-gradient(black, transparent);
  mask-border: url("border-mask.png") 30 fill / 20px;
  mask-border-slice: 25 fill;
}

Declare mask border properties after the mask shorthand when their values must be preserved.

mask-border-slice Example

This example demonstrates how different slicing offsets divide a source image. Because standardized mask border support is limited, the Browser Result uses border-image-slice to illustrate the same nine-slice geometry.

The demonstration uses an embedded SVG image with colored corner, edge, and center regions. This makes the effect of different slicing offsets easier to see.

HTML Example

<div class="mask-slice-demo">
  <div class="mask-slice-box slice-ten">10 Slice</div>
  <div class="mask-slice-box slice-twenty">20 Slice</div>
  <div class="mask-slice-box slice-thirty">30 Slice</div>
  <div class="mask-slice-box slice-fill">30 Slice with fill</div>
</div>

CSS Example

.mask-slice-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  padding: 20px;
  background-color: #f1f5f9;
}
.mask-slice-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  padding: 15px;
  border: 20px solid transparent;
  background-color: #fff;
  color: #1e293b;
  font-weight: bold;
  text-align: center;
  border-image-source: url("pattern-border.svg");
  border-image-width: 20px;
  border-image-repeat: stretch;
}
.slice-ten {
  border-image-slice: 10;
}
.slice-twenty {
  border-image-slice: 20;
}
.slice-thirty {
  border-image-slice: 30;
}
.slice-fill {
  border-image-slice: 30 fill;
}

The Browser Result uses an embedded SVG data image so no external image file is required.

Browser Result
10 Slice
20 Slice
30 Slice
30 Slice with fill

The examples show how different slicing offsets select different portions of the source image for the corners and edges. The final example includes the center region using fill.

This is a slicing demonstration, not a rendered mask border. The border-image-slice property uses the same nine-slice geometry, but it paints a border image rather than masking an element.

Actual mask-border-slice Declarations

.masked-ten {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 10;
  mask-border-width: 20px;
}
.masked-twenty {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 20;
  mask-border-width: 20px;
}
.masked-thirty {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30;
  mask-border-width: 20px;
}
.masked-fill {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
}

These declarations use the standardized mask-border-slice property. The image URL is illustrative and must point to an existing mask image.

Use Percentage Slicing

.masked-panel {
  mask-border-source: url("border-mask.png");
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
}

The slicing lines are positioned one-quarter of the source image's dimensions inward from its edges.

Use Different Side Offsets

.masked-panel {
  mask-border-slice: 10 20 30 40 fill;
}

The source image is divided using different offsets on each side.

Remove the Center Region

.masked-panel {
  mask-border-slice: 30;
}

Removing fill excludes the center region from the mask border image.

Common Mistakes

Using Pixel Units

.element {
  mask-border-slice: 30px;
}

The value 30px is invalid. Use the unitless number 30 or a percentage.

Using Negative Values

.element {
  mask-border-slice: -10;
}

Negative slicing values are invalid. Use zero or a positive value.

Using More Than Four Numeric Values

.element {
  mask-border-slice: 10 20 30 40 50;
}

The property accepts a maximum of four numeric slicing values.

Forgetting fill

The center region is discarded when fill is omitted. Add fill when the center image region should contribute to the mask.

Confusing Slice Values with Border Widths

The mask-border-slice property controls where the source image is divided. The mask-border-width property controls the widths of the rendered mask border regions.

Measuring Percentages Against the Element

Percentage slicing offsets are calculated from the source image dimensions, not the HTML element's dimensions.

Expecting fill to Make the Center Opaque

The fill keyword includes the center region, but its transparency still depends on the source image and masking mode.

Expecting the Property to Create a Mask Border

A slicing declaration alone does not provide a mask border source. Use mask-border-source or the shorthand to supply an image.

Overwriting the Property with a Shorthand

.element {
  mask-border-slice: 30 fill;
  mask-border: url("border-mask.png");
}

The later shorthand resets the slicing value to 0.

Assuming Universal Browser Support

The standardized mask-border-slice property has limited browser support. Test the intended result before using it in production.

Important Considerations

Keep the following points in mind when using mask-border-slice:

  • The property divides a mask border source image into nine regions.
  • Its initial value is 0.
  • The property is not inherited.
  • It accepts one to four nonnegative numbers or percentages.
  • Negative values are not permitted.
  • CSS length values such as 20px are not permitted.
  • Numbers and percentages can be combined in the same declaration.
  • Numbers use the source image's coordinate system.
  • Percentages are calculated from the source image dimensions.
  • Top and bottom percentages use the source image's height.
  • Left and right percentages use the source image's width.
  • One value applies to all four sides.
  • Two values apply to the vertical and horizontal sides.
  • Three values apply to the top, horizontal sides, and bottom.
  • Four values follow the top, right, bottom, and left order.
  • The corner regions are positioned at the corners of the mask border area.
  • The edge regions are stretched or repeated according to mask-border-repeat.
  • The center region is discarded unless fill is specified.
  • The fill keyword can appear before or after the numeric values.
  • The transparency of the included center depends on the source image and masking mode.
  • The property does not create a mask border without a source image.
  • The property does not determine the rendered mask border width.
  • It is a longhand component of the mask-border shorthand.
  • The shorthand resets omitted slicing values to 0.
  • The mask shorthand also resets mask border properties.
  • The property does not change the element's layout dimensions.
  • The standardized property has limited browser support.
  • Test the intended masking effect in the browsers your website supports.

Browser Support

The CSS mask-border-slice property has Limited availability and is not part of Baseline because it is not consistently supported across major browsers.

Some browsers support related mask border functionality through the legacy -webkit-mask-box-image property, but this does not guarantee support for the standardized mask-border-slice longhand.

For current compatibility information, visit Can I Use? and search for mask-border-slice.

When broad compatibility is required, consider border-image-slice for decorative borders or supported CSS and SVG masking techniques for transparency effects.

Specifications

The mask-border-slice property is defined in CSS Masking Module Level 1.

CSS Masking Module Level 1: mask-border-slice

The specification defines the accepted values, slicing geometry, and behavior of the optional fill keyword.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: mask-border-slice