Gradient Border

What Is the CSS Gradient Border Generator?

Create gradient borders on any element with the CSS mask technique, which keeps rounded corners and lets the inside stay transparent. Choose colors, angle, border width and radius with a live preview.

Why Use This Tool?

CSS has no gradient value for the border property, but a gradient layer masked down to a ring achieves the same effect. This tool generates that code for you with customizable gradient colors and direction.

How to Use This CSS Gradient Border

  1. Pick your gradient colors — Choose two or more colors for your border gradient. Use complementary or analogous colors for the best visual results.
  2. Set the gradient direction — Choose the angle or direction — diagonal gradients (135°) feel more dynamic than horizontal or vertical ones.
  3. Adjust border width and radius — Set the ring thickness and corner rounding to match your design; the ring follows the radius exactly.
  4. Copy the CSS — Copy the .gradient-border rule and its ::before rule. The ::before rule ends with pointer-events: none, so links, buttons and text inside the box stay clickable (see the worked example).

Worked example: what the copied CSS does, and why it turns off pointer events

This generator uses the mask technique, not border-image or background-clip. The element gets your fill color, and a ::before pseudo-element covering it (position: absolute; inset: 0) carries the gradient. That pseudo-element's padding equals your border width. Two masks are combined with mask-composite: exclude (-webkit-mask-composite: xor for WebKit). Together they cut away the content box, so only a ring as thick as the padding stays visible, and it follows border-radius. We rendered the default output in Chromium 141 on October 12, 2026. The ring pixels came out as gradient colors and the inside as the fill color, as intended.

Why the ::before rule ends with pointer-events: none. The masked-out middle is invisible, but the pseudo-element still sits on top of everything inside the box. On October 12, 2026 a button, a link and a line of text inside the generated box received nothing: a click on the button did not fire and the browser reported the box as the element under the pointer. The generated rule now includes pointer-events: none. With the copied CSS in Chromium 141 on October 13, the button and the link are the elements under the pointer, the click fires, and the ring still paints in the gradient colours.

Mask vs background-clip vs border-image

TechniqueRounded cornersSee-through insideNotes
Mask on a pseudo-element (this tool)YesYes: the inside can stay transparentNeeds position: relative on the box and pointer-events: none on the pseudo-element
Two backgrounds with background-clip: padding-box, border-boxYesNo: the fill must be an opaque colorNo extra element. The gradient sits behind a transparent border.
border-imageNo: corners stay squareYesThe spec has the border image draw in place of the border style, and it isn't clipped by border-radius

Support: the standard mask and mask-composite properties are in Chrome and Edge 120+, Firefox 53+ and Safari 15.4+, according to MDN's compatibility data. The prefixed -webkit-mask-composite: xor line covers older Chromium and Safari versions. Keep both lines, in the order the tool writes them.

Frequently Asked Questions

How do gradient borders work in CSS?
This tool puts the gradient on a ::before pseudo-element that covers the box, gives it padding equal to the border width, and uses two masks with mask-composite: exclude to cut away the middle, leaving a gradient ring that follows border-radius. Another common method uses two backgrounds clipped to padding-box and border-box.
Can I animate gradient borders?
Yes, though this tool does not generate the animation. Two common ways: give the ::before an oversized gradient (background-size: 200% 200%) and animate background-position, or register the angle as a custom property with @property and animate it to rotate the gradient.
Is there a simpler alternative?
For simple cases, border-image: linear-gradient(...) works, but it doesn't support border-radius. The background-clip technique works with rounded corners.
How do I create a gradient border in CSS?+
There are two main techniques. The border-image approach uses border-image: linear-gradient(...) 1, but it doesn't support border-radius. The background-clip approach uses two backgrounds — one gradient with background-clip: border-box, one solid with background-clip: padding-box — and transparent borders to reveal the gradient underneath. This method supports border-radius.
Can gradient borders have rounded corners?+
Yes with the mask technique this tool uses, and with the two-background (background-clip) technique. Not with border-image: the border image is not clipped by border-radius, so its corners stay square.
Do gradient borders affect performance?+
For static borders the cost is small: one extra pseudo-element with a gradient and a mask. Animating the gradient repaints it every frame, so keep animated gradient borders to a few elements.
How do I make a gradient border in CSS?+
CSS border property doesn't support gradients directly. The workaround uses a gradient background on the element with background-clip: padding-box on an inner layer, or border-image: linear-gradient(...) which has more limited border-radius support.
Does gradient border work with border-radius?+
Yes. This tool uses the mask technique, which follows border-radius. The border-image technique does not: its corners stay square.

📖 Learn More

Related Article The Complete Guide to CSS Gradients → Related Article How to Create CSS Gradient Borders →

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service