CSS mask-border-source Property

The CSS mask-border-source property specifies the image used to create a mask around an element's border.

The source can be an external image, an SVG image, or a CSS-generated image such as a gradient. The browser divides the source into regions using mask-border-slice, then uses those regions to construct a mask that controls which parts of the element are visible.

mask-border-source Syntax

The mask-border-source property accepts an image value or the keyword none.

Basic Syntax

selector {
  mask-border-source: none;
}

External Image

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

SVG Image

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

Linear Gradient

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

Radial Gradient

.element {
  mask-border-source: radial-gradient(circle, black 40%, transparent 80%);
}

No Source Image

.element {
  mask-border-source: none;
}

CSS-Wide Keywords

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

The initial value is none, meaning no mask border source image is specified.

Property Values

Value Description
none Specifies that no mask border source image is used.
url() References an external image, including supported raster and SVG image formats.
linear-gradient() Creates a gradient image that can be used as the mask border source.
radial-gradient() Creates a radial gradient image for the mask border source.
conic-gradient() Creates a conic gradient image for the mask border source.
initial Resets the property to none.
inherit Inherits the computed value from the parent element.
unset Resets the property to none 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 none
Inherited No
Applies to All elements, with SVG-specific applicability rules
Computed value As specified, with image URLs made absolute
Animation type Discrete
Accepted value type none or <image>
Multiple source layers No, a single mask border source is specified
Shorthand property mask-border
Browser availability Limited availability

How It Works

The mask-border-source property provides the image from which a mask border is constructed.

Unlike a normal border image, which paints decorative artwork, a mask border controls the visibility of an element through transparency or luminance values.

Step 1: Select a Source Image

.masked-panel {
  mask-border-source: url("border-mask.png");
}

The browser uses the referenced image as the source for the mask border.

Step 2: Divide the Image

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

The image is divided into nine regions. The fill keyword preserves the center region.

Step 3: Set the Mask Border Width

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

The browser uses 20-pixel-wide mask border regions when positioning the sliced image.

Step 4: Control Repetition

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

The edge regions repeat, with their dimensions adjusted to fit a whole number of repetitions.

Step 5: Apply the Mask

The browser uses the resulting mask border image to determine which portions of the element are visible. The effect depends on the source image's transparency or luminance and the selected masking mode.

Important Consideration

The source image alone does not define how it should be sliced, sized, or repeated. The related mask border properties control those details.

Image Sources

The mask-border-source property can reference supported image formats through the CSS url() function.

PNG Image

.element {
  mask-border-source: url("images/border-mask.png");
}

PNG images are useful when the mask border requires transparent or partially transparent regions.

SVG Image

.element {
  mask-border-source: url("images/border-mask.svg");
}

SVG images can provide scalable shapes and precise edge patterns.

WebP Image

.element {
  mask-border-source: url("images/border-mask.webp");
}

WebP images can contain transparency and may provide smaller file sizes than some alternative raster formats.

Absolute Image URL

.element {
  mask-border-source: url("https://www.example.com/images/border-mask.png");
}

Absolute URLs can reference images hosted on another server. Cross-origin image loading and security restrictions may affect whether the resource can be used.

Relative Image URL

.element {
  mask-border-source: url("../images/border-mask.png");
}

Relative URLs are resolved relative to the stylesheet containing the declaration, not necessarily the HTML document.

Choosing an Appropriate Image

A useful mask border source should be designed so its corners, edges, and optional center can be sliced and reconstructed without unwanted gaps or distortion.

Important Consideration

An image that works well as a background does not necessarily work well as a mask border. Consider its transparency, proportions, and the locations of the slicing lines.

Gradient Sources

CSS gradients produce image values and can be used as mask border sources without requiring external files.

Linear Gradient

.element {
  mask-border-source: linear-gradient(to right, black, transparent);
}

This creates an image that transitions from opaque black to transparent.

Radial Gradient

.element {
  mask-border-source: radial-gradient(circle, black 40%, transparent 80%);
}

This creates a circular gradient with a central opaque region and a transition toward transparency.

Conic Gradient

.element {
  mask-border-source: conic-gradient(black, transparent, black);
}

This creates a gradient whose color transitions rotate around a central point.

Repeating Linear Gradient

.element {
  mask-border-source: repeating-linear-gradient(
    90deg,
    black 0 10px,
    transparent 10px 20px
  );
}

The repeating gradient creates alternating opaque and transparent stripes that can contribute to a patterned mask border.

Gradient with Slicing

.element {
  mask-border-source: radial-gradient(circle, black 50%, transparent 100%);
  mask-border-slice: 25% fill;
  mask-border-width: 20px;
  mask-border-repeat: stretch;
}

The generated gradient is sliced and applied using the same mask border geometry as an external image.

Important Consideration

The resulting transparency depends on both the gradient's colors and the selected masking mode. In alpha mode, a fully opaque white region and a fully opaque black region provide the same mask opacity.

Alpha and Luminance Masking

The mask-border-mode property determines how the source image is interpreted when calculating the mask.

Alpha Masking

.element {
  mask-border-source: linear-gradient(black, transparent);
  mask-border-mode: alpha;
}

In alpha mode, the browser uses the image's transparency values. Opaque regions reveal the corresponding portions of the element, while transparent regions conceal them.

Luminance Masking

.element {
  mask-border-source: linear-gradient(black, white);
  mask-border-mode: luminance;
}

In luminance mode, the browser uses the source image's brightness together with its alpha values. White regions produce stronger mask coverage than black regions.

Alpha and Luminance Comparison

Source Region Alpha Mode Luminance Mode
Opaque white Fully reveals Fully reveals
Opaque black Fully reveals Fully conceals
Transparent Fully conceals Fully conceals
Partially transparent Partially reveals Depends on brightness and transparency

Choose the Appropriate Mode

Use alpha when the source image is designed primarily around transparency. Use luminance when its brightness values are intended to control visibility.

Important Consideration

The initial value of mask-border-mode is alpha. A black-to-white gradient without transparency will not create a brightness-based fade unless luminance mode is selected.

Source Images and Slicing

The mask-border-source and mask-border-slice properties work together to determine which parts of the source image are used.

Nine-Slice Layout

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

Using a Single Slice Value

.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 each edge.

Using Percentage Slices

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

The slicing lines are positioned 25% inward from each edge of the source image.

Preserving the Center

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

The fill keyword includes the center region in the mask. Without it, the center region of the source image is discarded.

Setting the Rendered Width

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

The source image is sliced at the specified offsets, while the mask border regions are rendered at the specified width.

Extending Beyond the Border Box

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

The mask border area extends 10 pixels beyond each side of the element's border box.

Important Consideration

Slicing values are based on the source image's dimensions or coordinate system. They are not based on the rendered size of the element.

Using the mask-border Shorthand

The mask-border-source 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 url("border-mask.png") portion specifies the source image.

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;
}

Gradient Source in the Shorthand

.element {
  mask-border: linear-gradient(black, transparent) 25% fill / 20px stretch alpha;
}

Override the Source

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

The later longhand declaration replaces the source image while preserving the other mask border settings.

Shorthand Reset Behavior

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

The later shorthand resets mask-border-source to none because no source image is included.

Interaction with mask

.element {
  mask-border-source: url("border-mask.png");
  mask: linear-gradient(black, transparent);
}

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

Correct Declaration Order

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

Place the mask border declaration after the mask shorthand when both are needed.

mask-border-source Example

This example compares three different source images that can be used for a mask border. Because standardized mask border support is limited, the Browser Result uses border-image-source to demonstrate how different source images affect a sliced border.

The example uses embedded SVG images so the result does not depend on external files. The demonstration illustrates source image selection and slicing, but it paints decorative borders rather than applying transparency masks.

HTML Example

<div class="mask-source-demo">
  <div class="mask-source-box source-solid">Solid Source</div>
  <div class="mask-source-box source-pattern">Pattern Source</div>
  <div class="mask-source-box source-gradient">Gradient Source</div>
</div>

CSS Example

.mask-source-demo {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  padding: 20px;
  background-color: #f1f5f9;
}
.mask-source-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-slice: 30;
  border-image-width: 20px;
  border-image-repeat: round;
}
.source-solid {
  border-image-source: linear-gradient(#2563eb, #2563eb);
}
.source-pattern {
  border-image-source: repeating-linear-gradient(
    45deg,
    #2563eb 0 10px,
    #93c5fd 10px 20px
  );
}
.source-gradient {
  border-image-source: linear-gradient(135deg, #2563eb, #059669);
}
Browser Result
Solid Source
Pattern Source
Gradient Source

The three examples demonstrate how a solid image, a repeating pattern, and a gradient can produce different results when used as the source for a sliced border.

This is a source image demonstration, not a rendered mask border. The standardized mask-border-source property uses image data to control visibility rather than painting decorative colors.

Actual mask-border-source Declarations

.masked-solid {
  mask-border-source: linear-gradient(black, black);
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
}
.masked-pattern {
  mask-border-source: repeating-linear-gradient(
    45deg,
    black 0 10px,
    transparent 10px 20px
  );
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
}
.masked-gradient {
  mask-border-source: linear-gradient(black, transparent);
  mask-border-slice: 30 fill;
  mask-border-width: 20px;
}

These declarations demonstrate how CSS-generated images can be used as mask border sources. Their visible effects depend on browser support and the other mask border settings.

Use an External Image

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

The source image is divided and applied to the mask border regions.

Switch to an SVG Source

.masked-panel {
  mask-border-source: url("border-mask.svg");
}

The SVG replaces the previous source image without changing the other mask border properties.

Remove the Source

.masked-panel {
  mask-border-source: none;
}

The element no longer uses a mask border source image.

Common Mistakes

Using a Color Instead of an Image

.element {
  mask-border-source: red;
}

A plain color is not a valid source value. Use an image or a CSS gradient.

Using an Incorrect Image Path

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

If the image cannot be loaded, the intended mask border effect will not be available. Check the file path and resource accessibility.

Confusing mask-border-source with mask-image

The mask-image property specifies mask layers for an element. The mask-border-source property supplies an image for the nine-slice mask border system.

Expecting the Source to Define Slicing

The source image does not automatically establish the desired slicing offsets. Use mask-border-slice to divide the image appropriately.

Forgetting the fill Keyword

The center region of the source image is discarded unless fill is included in mask-border-slice.

Assuming Black Always Means Transparent

In alpha mode, opaque black is fully opaque as a mask. Black conceals the element in luminance mode.

Using Multiple Comma-Separated Sources

.element {
  mask-border-source: url("first.png"), url("second.png");
}

The property accepts a single image value, not a comma-separated list of mask layers.

Overwriting the Source with a Shorthand

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

The later shorthand resets the source to none.

Confusing a Mask Border with a Decorative Border

A mask border controls visibility. Use border-image-source when the goal is to paint a decorative border image.

Assuming Universal Browser Support

The standardized mask-border-source property has limited browser support. Test the intended effect before relying on it in production.

Important Considerations

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

  • The property specifies the image used to construct a mask border.
  • Its initial value is none.
  • The property is not inherited.
  • It accepts none or a valid CSS image value.
  • Supported image sources can include raster images, SVG images, and CSS gradients.
  • CSS gradients can create mask border sources without external files.
  • The property accepts a single source image, not multiple comma-separated layers.
  • Image URLs must point to accessible resources.
  • Relative URLs in stylesheets are resolved relative to the stylesheet location.
  • Cross-origin resource restrictions can affect image loading.
  • The source image should be designed for nine-slice rendering.
  • The mask-border-slice property divides the source into corners, edges, and a center.
  • The center region is discarded unless fill is specified.
  • The mask-border-width property controls the rendered mask border region widths.
  • The mask-border-repeat property controls how edge regions are stretched or repeated.
  • The mask-border-outset property controls how far the mask border area extends beyond the border box.
  • The mask-border-mode property controls alpha or luminance interpretation.
  • In alpha mode, source transparency controls the mask.
  • In luminance mode, brightness and transparency both affect the mask.
  • The source image does not change the element's layout dimensions.
  • The property is a longhand component of the mask-border shorthand.
  • The shorthand resets an omitted source to none.
  • The mask shorthand also resets mask border properties.
  • The standardized property has limited browser support.
  • Legacy prefixed mask border features are not identical to every standardized feature.
  • Provide a suitable fallback when the masking effect is essential.

Browser Support

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

Some browsers support related functionality through the legacy -webkit-mask-box-image property. However, this does not guarantee support for the standardized mask-border-source longhand or the complete standardized mask border system.

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

When broad compatibility is required, consider supported mask-image techniques for transparency effects or border-image-source for decorative borders that do not require masking.

Specifications

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

CSS Masking Module Level 1: mask-border-source

The specification defines the accepted image values and the role of the source image in constructing a mask border.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: mask-border-source