CSS Gradient Borders: 3 Techniques That Work With Rounded Corners
Create a CSS gradient border that respects border-radius: border-image, the padding-box double background, and a mask trick for fully transparent centers.
Read GuideGradient
Create CSS gradient borders that work with rounded corners and copy the code.
Gradient
Most tricks for colorful outlines break on rounded corners, but this gradient border generator uses the padding-box and border-box double-background technique, so your border follows any border-radius cleanly. Choose two colors, an angle, a border width and a corner radius, then watch the preview card update. The output is plain CSS with no extra wrapper elements or pseudo-elements, which makes it a practical choice for developers styling cards, buttons, inputs and avatars.
The technique works by stacking two backgrounds: a solid fill clipped to the padding box sits on top of a gradient that fills the border box, and a transparent border lets the gradient show through around the edges. That means the inner fill must be a solid color, so set it to exactly the background color of the card. If you need a see-through center, switch to a mask-based or pseudo-element approach instead.
FAQ
Give the element a transparent border, then set two background layers: a solid color with background-clip padding-box and a gradient with background-clip border-box. The solid layer covers the middle, so the gradient only shows through the transparent border. This approach respects border-radius and needs no extra HTML.
When border-image is used, the browser draws the border from the image and ignores border-radius for the border itself, so the corners stay square. The background-clip method avoids this because the gradient is a background, and backgrounds follow rounded corners. That is why it is the usual choice for rounded gradient borders.
Not with the padding-box and border-box method, because the inner solid layer is what hides the middle of the gradient. For a transparent center, developers typically use a pseudo-element with a CSS mask that cuts out the content area, or an inline SVG stroke. These options need more code but let the page background show through.
For interface elements such as cards and inputs, 1px to 3px usually looks refined, while 4px or more reads as a decorative frame. Thin borders show less of the gradient, so pick colors with a clear difference in hue or lightness if you want the blend to be noticeable. Thicker borders suit avatars and featured cards where the gradient is the focal point.
Learn more
Create a CSS gradient border that respects border-radius: border-image, the padding-box double background, and a mask trick for fully transparent centers.
Read GuideBuild an animated gradient in CSS with background-position keyframes, calm timing, prefers-reduced-motion support, GPU-friendly layers and @property angles.
Read Guide