CSS Gradient Border Generator

Create gradient borders using border-image and pseudo-element techniques with support for border-radius.

Gradient Border

What is a CSS Gradient Border?

A CSS gradient border is a border painted with a smooth color gradient instead of a single solid color. It is a popular way to make cards, buttons, and hero panels feel more premium without adding images or extra elements. There are two well-known ways to build one, and this generator produces both.

The primary technique uses a double background. The element is given a transparent border, a gradient is painted twice, and the two layers are clipped differently: the first is clipped to the padding box and the second to the border box. Because the second layer is clipped to the border box, it shows only in the border area, which creates a gradient ring around the content. This approach fully supports border-radius, so the gradient follows rounded corners cleanly.

The alternative technique uses the border-image property with a gradient and a slice value of 1, for example border-image: linear-gradient(...) 1;. It is very concise, but border-image does not respect border-radius, so it is best for straight-edged rectangles. The generator includes it as a commented fallback so you can pick whichever fits.

The tool supports linear, radial, and conic gradients, an adjustable border width from 1 to 20 pixels, two colors chosen with pickers or hex input, and six ready-made presets. It runs entirely client-side and outputs a ready .gradient-border class plus a .gradient-border-image alternative.

Key Concepts

  • Double background — two gradient layers using background-origin and background-clip set to padding-box, border-box.
  • Transparent border — the solid border is made transparent so the background layer beneath it shows through.
  • border-image — a one-line alternative using a gradient plus a slice value of 1.
  • border-radius — supported by the double-background method, ignored by border-image.
  • Border width — controls the thickness of the gradient ring, from 1 to 20 pixels.
  • Gradient type and angle — linear and conic honor the angle; radial is always circular.

How to Use

  1. Load a preset or set the type — Pick one of the six presets, or choose Linear, Radial, or Conic from the gradient type dropdown.
  2. Pick the two colors — Use the color pickers or type hex values into Color 1 and Color 2.
  3. Set the angle — Drag the angle slider to rotate the gradient for linear and conic types.
  4. Adjust the border width — Move the border width slider between 1 and 20 pixels until the ring looks right.
  5. Copy the CSS — Click Copy CSS and paste either the .gradient-border class or the border-image alternative.

Preset and Technique Reference

Preset Color 1 Color 2 Angle Type Border width
Ocean#3b82f6#06b6d445Linear4px
Sunset#f97316#e11d48135Linear4px
Neon#22c55e#a855f790Linear4px
Gold#f59e0b#b45309180Linear4px
Rainbow#ef4444#8b5cf60Conic4px
Purple Haze#7c3aed#ec489945Linear4px
Technique Key properties border-radius Best for
Double backgroundbackground-origin/clip: padding-box, border-boxSupportedRounded cards and buttons
border-imageborder-image: gradient 1Not supportedStraight-edged panels

Worked Examples

  • Default linear — outputs a 4px transparent border and linear-gradient(45deg, #3b82f6, #8b5cf6) with a 16px radius.
  • Ocean preset — uses linear-gradient(45deg, #3b82f6, #06b6d4) at 4px.
  • Sunset preset — uses linear-gradient(135deg, #f97316, #e11d48) at 4px.
  • Rainbow preset — switches to conic and outputs conic-gradient(from 0deg, #ef4444, #8b5cf6).
  • Radial type — ignores the angle and produces radial-gradient(circle, #3b82f6, #8b5cf6).
  • Thicker ring — setting the border width to 10 outputs border: 10px solid transparent; and correspondingly pads the preview.

Tips and Common Mistakes

  • Use the double-background class when you need rounded corners — the border-image method ignores border-radius entirely.
  • Keep the transparent border — changing border: 4px solid transparent to a color hides the gradient ring.
  • Match the width in both border and padding — the preview adds matching padding so the inner content does not overlap the ring.
  • Remember radial has no angle — the angle slider only affects linear and conic gradients.
  • Use a real inner background — the element behind the gradient needs an opaque background so the ring reads as a border.
  • Do not mix the two classes — apply either .gradient-border or .gradient-border-image, not both.

Common Use Cases

Gradient borders add polish while staying lightweight. Here are some of the ways designers and developers apply them.

  1. Feature cards — outline pricing or feature cards with a subtle brand gradient.
  2. Buttons — create a ghost button with a gradient outline and transparent fill.
  3. Profile avatars — ring an avatar image with a gradient to signal a live or premium status.
  4. Dashboard widgets — separate panels visually without heavy shadows.
  5. Dark-mode accents — a bright gradient ring stands out against dark surfaces.
  6. Marketing banners — frame promotional content with an eye-catching outline.

Frequently Asked Questions

Does border-image work with border-radius?

The border-image property does not support border-radius. For rounded gradient borders, use the double-background approach included in the generated CSS as an alternative method.

Can I use this on any element?

Yes. The generated CSS can be applied to divs, buttons, cards, images, and any block-level element.

What is the difference between the two generated classes?

The .gradient-border class uses a transparent border with background-origin and background-clip set to padding-box, border-box so it supports rounded corners. The .gradient-border-image class uses border-image, which is shorter but does not support border-radius.

What border widths can I choose?

The border width slider ranges from 1 to 20 pixels and defaults to 4 pixels. The value is written into both the border declaration and the background clip ring.

Why is the angle slider missing for radial gradients?

A radial gradient is circular and has no direction, so the angle control only appears for linear and conic gradient types.

Which gradient types are supported?

Three types are supported: linear-gradient with an angle, radial-gradient drawn as a circle, and conic-gradient sweeping from a starting angle.

Do the presets change the border width?

Every preset loads its colors, angle, and gradient type and sets the border width to 4 pixels. You can adjust the width afterwards with the slider.

Is the generator free and private?

Yes. It is completely free and runs entirely in your browser. No colors or settings are uploaded, stored, or shared with any server.