CSS Reference ยท Filters, Masks and Shapes
The mask-border property
Reference for the CSS mask-border shorthand: slice an image into nine regions and use it as a mask along an element's border. Limited browser support.
The mask-border property masks an element using an image that is sliced into nine regions (four corners, four edges and a middle), exactly like border-image slices an image for a border. The parts of the element covered by the opaque areas of the mask stay visible. It is useful for decorative, irregular edges such as torn paper or stamps.
The property is a shorthand for mask-border-source, mask-border-slice, mask-border-width, mask-border-outset, mask-border-repeat and mask-border-mode.
Limited support. mask-border is defined in the CSS Masking specification, but browsers have not implemented it in the standard unprefixed form, and Chromium and Safari only offer the older -webkit-mask-box-image, which uses different slicing rules. Treat it as an enhancement and never as a requirement.
.stamp { mask-border: url(edge.svg) 30 / 30px round; }
Try it
This demo tests whether your browser understands the property, then applies it. If it does, only a ring along the edge of the box is visible, because the middle region is not filled. If not, you see a solid box and a note.
Syntax
mask-border: <'mask-border-source'> || <'mask-border-slice'>
[ / <'mask-border-width'>? [ / <'mask-border-outset'> ]? ]?
|| <'mask-border-repeat'> || <'mask-border-mode'>
- Initial values:
mask-border-source: none,mask-border-slice: 0,mask-border-width: auto,mask-border-outset: 0,mask-border-repeat: stretch,mask-border-mode: alpha - Applies to: all elements; in SVG, container elements (except
<defs>) and graphics elements - Inherited: no
- Animatable: as each longhand (slice, width and outset can be animated)
- Computed value: as each longhand
Values
| Longhand | Description |
|---|---|
mask-border-source |
The image: none, a url() or a gradient. |
mask-border-slice |
Four offsets (numbers or percentages) that cut the image into nine regions. The keyword fill also uses the middle region. |
mask-border-width |
The thickness of the border area the slices are drawn into. Defaults to auto (the slice size). |
mask-border-outset |
How far the mask area extends beyond the border box. |
mask-border-repeat |
stretch, repeat, round or space for the edge slices. |
mask-border-mode |
alpha (default) or luminance. |
Usage notes
- The middle is hidden unless you add
fill. Withoutfillin the slice, the central region of the image is not used, so the content inside the border area disappears. - Replaces the regular mask. When
mask-border-sourceis set, it works along withmask-image; the element is visible where all masks allow it. - Behaves like
border-image. The slicing, width, outset and repeat rules are the same ones you may know from borders. - Prefer alternatives today. For irregular edges that work everywhere, use
mask-imagewith gradients, SVG masks, orclip-path. - Feature-test it. Use
@supports (mask-border-source: none)so unsupported browsers get a normal element.
Browser support
Not supported unprefixed in the major browsers as far as we know; some engines expose only the legacy -webkit-mask-box-image. Check a compatibility table before using it.
Related
maskโ the supported mask shorthandmask-imageโ the practical alternativeborder-imageโ the same slicing model for bordersclip-pathโ hard-edged shapes- Lesson: Clip Paths and Masks