Colour · gradient recipeCSS gradient border — with rounded corners

border-image draws a gradient border but breaks border-radius. Two backgrounds are more reliable: a solid one under the content and the gradient under the border.

TextButtonBorderAnimation← Back to the builder
01Example02Code03Steps04Mistakes05Questions06Recipes07Related
01

Live example

change the colours — the code below follows
A card with a border
The border is a second background visible only in the border area. Rounded corners work as usual.
Recipe settings
Colours
#6C8CFF0%
#B18CFF100%
Open in the builder →
02

Ready code

the two-background trick keeps rounded corners
.gradient-border {
  border: 3px solid transparent;
  border-radius: 14px;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(90deg, #6c8cff 0%, #b18cff 100%) border-box;
}
03

Step by step

  1. 01
    border: 3px solid transparent
    Give the border a width and make it transparent — the background shows through it.
  2. 02
    linear-gradient(#fff, #fff) padding-box
    The first layer is the solid backing colour, limited to the padding box.
  3. 03
    linear-gradient(…) border-box
    The second layer is the gradient itself, stretched to the outer edge of the border.
  4. 04
    border-radius: 14px
    The radius applies to both layers at once.
04

Common mistakes

border-image and rounded corners

With border-image, border-radius is ignored. If you need corners, use two backgrounds.

Backing differs from the page

The first layer must match the colour under the card, otherwise a visible plate appears around the content.

Transparent card

The trick needs an opaque backing. Semi-transparent cards need a mask (mask-composite) — a separate technique.
05

Frequently asked

That is how the specification works: border-image replaces the normal border painting with an image, and corner rounding is not applied to that image. So a gradient border made with border-image always has sharp corners, whatever border-radius says. The two-background trick in this recipe avoids the limitation: the border stays transparent, the gradient is painted as a background beneath it, and the radius applies to both layers.
06

Other recipes

Updated

«» added to favorites