Gradient Border Button
Dark button with an animated gradient border.
<button class="relative px-6 py-3 rounded-xl text-white font-semibold text-sm"> <span class="absolute inset-0 rounded-xl bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500"></span> <span class="absolute inset-[2px] rounded-[10px] bg-slate-900"></span> <span class="relative">Get started</span> </button>
Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Sunset
Warm gradient for food, travel, or creative brands.
Ocean
Cool blues and teals suit SaaS, dev tools, and ocean themed sites.
Light
White inner surface for light layouts where the dark version feels heavy.
Where to use it
- ✓ Premium feature buttons
- ✓ AI tool CTAs
- ✓ Pro tier upgrades
- ✓ New feature announcements
About this gradient border button
Gradient borders are the premium framing device: a thin line of color flowing from indigo to pink around an otherwise dark button. This gradient border button builds the effect with two absolutely positioned spans: a gradient layer filling the button, and a dark inset layer covering everything except a 2px border.
The technique is pure Tailwind with no custom CSS. The outer span paints the gradient, the inner span (inset-[2px]) masks the center, leaving the gradient visible only at the edges. The text sits on top with relative positioning.
Gradient borders signal premium tiers, AI features, and new launches. They work best on dark buttons where the colorful edge pops. Keep the border thin: 2px is the sweet spot between visible and gaudy.
A plain bordered button communicates nothing beyond its label; it is a rectangle with an edge. Products selling a premium tier or an AI feature need the button itself to feel like an upgrade, and color alone cannot do that inside a 2px edge. The gradient border borrows the language of foil-stamped packaging and metal credit cards: a thin line of shifting color that signals this one is special before the user reads a word.
Two absolutely positioned spans do the work. The outer span fills the button with bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500, and the inner span at inset-[2px] paints bg-slate-900 over the center, masking everything except a 2px gradient edge. The label sits in a relative span above both layers. This mask technique exists because border-image, the obvious alternative, cannot follow border-radius curves.
Steer the gradient's direction to match the page's energy: to-r feels calm and horizontal, to-br adds diagonal motion. On light themes, swap the inner mask from slate-900 to white so the button reads as light with a colorful edge. For a living border, set background-size to 200% on the gradient span and animate background-position on a slow loop so the colors drift around the frame.
The classic error is giving the outer and inner layers the same border radius. A rounded-xl outer with a rounded-xl inner produces a border that looks thicker at the corners and thinner on the straights, because the inner curve does not sit concentrically inside the outer one. Shrink the inner radius by the border width (rounded-xl outside, roughly rounded-[10px] inside) so the gradient edge measures an even 2px all the way around.
Frequently asked questions
How do I make a gradient border in Tailwind?
Layer two absolute spans inside a relative button: a gradient span filling the button, and a background-colored span inset by 2px. The visible edge becomes the border.
Can I animate a gradient border?
Yes. Animate the background-position of the gradient span with keyframes, or rotate a conic gradient behind the button for a spinning border effect.
Why not use border-image for gradients?
border-image has poor border-radius support. The layered span technique respects rounded corners perfectly, which is why it is the standard approach.
How thick should a gradient border be?
2px is the sweet spot. Thicker than 3px and it stops reading as a frame and starts looking like a gradient button with a dark center. In this element the border thickness comes from the inset value on the dark layer, so change inset-[2px] to inset-[3px] if you want it slightly bolder.
Does the gradient border button work on light backgrounds?
The border itself works anywhere, but the dark inset layer must match your page background or the button looks like a dark box. For light layouts, change the inner span from bg-slate-900 to bg-white and switch the text to a dark color. The Light variant below shows exactly this setup.
Can I use rounded-full for a pill gradient border button?
Yes. Change both rounded-xl classes to rounded-full, and make the inner span's radius slightly smaller so the border thickness stays even all around. Because this technique layers backgrounds instead of using border-image, rounded corners of any size keep the gradient ring perfectly smooth.
Design notes
When to use
Use it for premium actions: Pro tier upgrades, AI feature launches, and new feature announcements where you want the button to feel special. The thin gradient edge reads as a quality signal, so it works best as the one standout button among plainer ones. It looks strongest on dark buttons where the colorful border pops.
What to avoid
Do not use it on light buttons, the gradient edge washes out and the effect disappears. Do not thicken the border past 2 to 3px or it stops looking like a frame and starts looking like a gradient button with a dark center.
Accessibility
White text on the dark inset keeps contrast strong, but verify it if you change the inset color. Keep the native button element so keyboard focus and activation work without extra code.
Customization tips
Change the gradient stops to your brand colors. Increase inset to 3px for a thicker border. For an animated border, add a slow background-position animation to the gradient span.