Gradient borders are one of those designs that look simple and are annoyingly hard in CSS. border-image ignores border-radius, and the popular “two backgrounds” trick needs an opaque fill. A newer value, background-clip: border-area, fixes this properly, and the last missing engine is about to ship it. The Firefox 162 developer release notes (Firefox 162 is in beta now and due on 8 December 2026) list border-area support for background-clip.
According to MDN’s browser compatibility data, border-area is already in Chrome 150 (and Chromium-based Edge) and Safari 18.2. With Firefox 162 it will work in every major engine. This tutorial explains what border-area does and gives you practical, copy-paste recipes with safe fallbacks.
What border-area does
MDN defines it like this: the background is painted within (clipped to) the area painted by the border, taking border-width and border-style into account but ignoring any transparency introduced by border-color.
In practice:
- Give the element a border with the width and style you want.
- Make the border colour
transparent. - Clip a background to
border-area. The background shows only where the border would be drawn: dashes, dots, double lines and rounded corners included.
Compare that with the other background-clip values:
| Value | Background is painted… |
|---|---|
border-box (default) |
under the border, padding and content |
padding-box |
inside the border |
content-box |
only behind the content |
text |
only inside the glyphs |
border-area |
only where the border is painted |
Recipe 1: a gradient border with a transparent middle
This is the case the old tricks could not handle: the inside stays see-through, so it works over images and patterned backgrounds.
<div class="frame">Gradient border, transparent inside</div>
.frame {
border: 6px solid transparent;
border-radius: 16px;
padding: 1.5rem;
background: conic-gradient(from 0deg, #f43f5e, #f59e0b, #10b981, #3b82f6, #f43f5e);
background-clip: border-area;
background-origin: border-box;
}
Why background-origin: border-box? By default a background is positioned and sized from the padding box, so the gradient would be sized to the inner area and repeat into the border. Starting it at the border box makes it cover the border cleanly.
Recipe 2: a gradient border on a solid card
For a card with an opaque fill, use two background layers: a solid layer clipped to the padding box, and the gradient clipped to the border area.
.card {
border: 3px solid transparent;
border-radius: 12px;
padding: 1.25rem;
background-image:
linear-gradient(#ffffff, #ffffff), /* fill */
linear-gradient(135deg, #6366f1, #ec4899); /* border */
background-clip: padding-box, border-area;
background-origin: border-box;
}
Layers are listed top to bottom, and each comma-separated background-clip value matches its layer. You could already approximate this with padding-box, border-box, but border-area also respects border-style, which leads to the next recipe.
Recipe 3: dashed and dotted gradient borders
Because border-area follows the painted border shape, dashed and dotted borders pick up the gradient too. That used to need SVG.
.dropzone {
border: 4px dashed transparent;
border-radius: 14px;
padding: 2rem;
text-align: center;
background: linear-gradient(90deg, #22d3ee, #a855f7);
background-clip: border-area;
background-origin: border-box;
}
.dropzone.is-over {
background: linear-gradient(90deg, #f97316, #facc15);
background-clip: border-area;
background-origin: border-box;
}
That is a file-upload drop zone with a gradient dashed outline, using no images.
Recipe 4: an animated “glow” border
Combine border-area with a registered custom property to animate a conic gradient’s angle:
@property --angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
.glow {
border: 3px solid transparent;
border-radius: 999px;
padding: 0.6rem 1.4rem;
background: conic-gradient(from var(--angle), #3b82f6, #a855f7, #ec4899, #3b82f6);
background-clip: border-area;
background-origin: border-box;
animation: spin 4s linear infinite;
}
@keyframes spin {
to { --angle: 360deg; }
}
@media (prefers-reduced-motion: reduce) {
.glow { animation: none; }
}
Always include the prefers-reduced-motion override for decorative motion.
Safe fallbacks with @supports
In a browser without border-area, the declaration is invalid and ignored, so the background falls back to border-box and fills the whole element with your gradient, which is rarely what you want. Use a feature query so unsupported browsers get a plain solid border instead:
.frame {
border: 6px solid #6366f1; /* fallback: solid border */
border-radius: 16px;
padding: 1.5rem;
}
@supports (background-clip: border-area) {
.frame {
border-color: transparent;
background: conic-gradient(from 0deg, #f43f5e, #f59e0b, #10b981, #3b82f6, #f43f5e);
background-clip: border-area;
background-origin: border-box;
}
}
You can also check support from JavaScript:
const hasBorderArea = CSS.supports('background-clip', 'border-area');
document.documentElement.classList.toggle('has-border-area', hasBorderArea);
Gotchas
- Write
background-clipafter thebackgroundshorthand. The shorthand resetsbackground-clipto its initial value, so abackground:declaration that comes later undoes your clip. That is why the recipes repeatbackground-clipafter eachbackgroundchange. - The border colour must be transparent (or semi-transparent) to see the background.
border-areaignores the colour’s transparency when deciding the painted area, but the border itself still paints on top of the background. background-colorfollows the bottom layer’s clip. If the gradient is the only layer and is clipped toborder-area, abackground-coloris clipped there too. Use a separate fill layer (Recipe 2) for solid interiors.- The root element ignores
background-clip, as with every value of this property. - Accessibility: a gradient border is decoration. Do not rely on it alone to show state such as errors or focus. Pair it with text, icons or a visible
:focus-visibleoutline.
When will it be “Baseline”?
A feature becomes Baseline Newly available once it works in the latest Chrome, Edge, Firefox and Safari. With Chrome 150 and Safari 18.2 already shipping it, Firefox 162’s stable release on 8 December 2026 should complete the set. Until your audience has updated, keep the @supports fallback. It costs a few lines and degrades gracefully to a solid border.
Takeaway
background-clip: border-area finally gives CSS a native, tidy way to paint gradients, images or animations only in the border, and it respects rounded corners, dashes and dots. Start using it today behind @supports, and once Firefox 162 is out you can rely on it in every major browser.
Sources: Firefox 162 release notes for developers (MDN) · MDN: background-clip · MDN browser-compat-data: background-clip
