CSS Portal

CSS mask-border-width Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The mask-border-width property controls the thickness of the border regions when a mask image is applied using the mask-border nine-slice model. Rather than changing the visible border of an element, it affects how the source mask is divided into corner, edge, and center regions and therefore how much of the element’s box those regions cover. Changing these widths changes which portions of the mask are stretched, repeated, or preserved at the corners, and thus directly influences the visual shape of the masked area around the element’s edges.

When rendering, mask-border-width works together with the image that supplies the border and the slicing rules that cut that image into regions. The division of the source graphic is specified by mask-border-slice, and the image itself comes from mask-border-source. How the edge tiles behave — whether they repeat, stretch, or round — is determined by mask-border-repeat. Because of these interactions, altering the border widths can expose more or less of the central area of the mask, make corner artwork consume a larger proportion of the box, or force edges to tile more or less frequently, depending on the combination of slicing, source resolution, and repeat rules.

In layout terms, the property affects how the mask overlays the element’s box but does not itself change layout metrics like margin or padding; however, it can visually overlap or underlap the element’s existing CSS borders and background. When the specified border widths are large relative to the element’s size, the mask’s corner and edge regions can compete for space and the rendering engine must decide whether to clamp, scale, or collapse regions to fit — behavior that has a direct visual impact on small or heavily scaled elements. It’s also common to consider this property alongside your element sizing model (for example, box-sizing) to reason about how the mask will appear against an element whose box sizing or border widths are nonstandard.

Practically, use mask-border-width to control the visual prominence and fidelity of decorative masked borders: make corners large enough to preserve artwork, or reduce edge widths so that the mask’s interior shows more clearly. Because the visual outcome depends on the source image resolution and the other mask-border properties, test with representative sizes and DPI so corners don’t blur or edges don’t tile awkwardly. Finally, be mindful that very complex or large mask-border regions may add to rendering cost, particularly when repeatedly tiled or when animating changes to the border widths.

Definition

Initial value
auto
Applies to
all elements; In SVG, it applies to container elements excluding the <defs> element and all graphics elements
Inherited
no
Computed value
as specified, but with relative lengths converted into absolute lengths
Animatable
yes
JavaScript syntax
object.style.maskBorderWidth

Syntax

mask-border-width: <length> | <percentage> | auto | inherit | initial | unset;

Values

  • <length>Specifies the width in units like px, em, rem, etc. You can provide one, two, three, or four values, similar to border-width.
  • <percentage>Specifies the border width as a percentage of the corresponding mask image dimensions.
  • auto The browser calculates the mask border width automatically based on the mask image.
  • inherit Inherits from the parent element.
  • initial Sets to the default value.
  • unsetResets the property to its inherited or initial value depending on the context.

Example

<div class="masked-box">
Masked Content
</div>
.masked-box {
    width: 300px;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    background-color: #4CAF50;
    
    mask-image: url('mask-border.png');
    mask-repeat: no-repeat;
    mask-slice: 30;
    mask-border-width: 20px;
    mask-border-source: url('mask-border.png');
}

Browser Support

The following information will show you the current browser support for the CSS mask-border-width property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported in some modern browsers, but not all.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 28th December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!