Gradient border
Also called rainbow border, rainbow button, or neon gradient card
A border painted with a multicolor gradient, often flowing slowly along the edge with a matching glow, used to feature one button or card.
import type { ReactNode } from 'react';
import { motion, useReducedMotion } from 'motion/react';
// The first color repeats at the end, so the tiles join without a seam.
const RAINBOW =
'bg-[linear-gradient(90deg,#ef4444,#f59e0b,#22c55e,#3b82f6,#a855f7,#ec4899,#ef4444)] bg-size-[50%_100%]';
function Flow() {
const reduceMotion = useReducedMotion();
return (
// Two gradient tiles wide; sliding by half (one tile) loops seamlessly.
<motion.span
aria-hidden
animate={reduceMotion ? undefined : { x: ['0%', '-50%'] }}
transition={{ duration: 4, ease: 'linear', repeat: Infinity }}
className={`absolute inset-y-0 left-0 w-[200%] ${RAINBOW}`}
/>
);
}
export function RainbowButton({ children }: { children: ReactNode }) {
return (
<button type='button' className='relative rounded-full'>
{/* The glow: a blurred copy of the strip, clipped to the button's shape. */}
<span
aria-hidden
className='absolute inset-x-3 -bottom-2 h-3/4 overflow-hidden rounded-full opacity-60 blur-[14px]'
>
<Flow />
</span>
{/* 2px of padding is the border; the strip shows only in that gap. */}
<span className='relative block overflow-hidden rounded-full p-[2px]'>
<Flow />
<span className='relative flex h-12 items-center rounded-full bg-neutral-950 px-7 font-semibold text-white'>
{children}
</span>
</span>
</button>
);
}Give the "Start building" button a flowing rainbow border: a 2px border made from a linear gradient of red, amber, green, blue, purple, and pink that slides along the edge in a 4-second linear loop, around the button’s dark fill. Put a blurred copy of the gradient (14px blur, 60% opacity) just under the button as a glow. Move the gradient with transform instead of background-position, and keep it still when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Gradient border?
A gradient border swaps a solid outline for a band of several colors. The colors can sit still, but they usually flow along the edge in a slow loop, and a blurred copy of the same gradient often sits underneath as a soft colored glow. It marks a featured plan, a new-feature card, or the main call to action.
CSS has no gradient value for border-color, so the usual build uses two layers. An outer wrapper gets the gradient as its background and 1 to 2px of padding, and the inner element covers the middle with the page color and a slightly smaller radius, so only the padding shows. To make the colors flow, slide a gradient strip twice the element’s width with transform, or rotate a conic-gradient behind the element. A single element can also do it with two backgrounds and background-clip: padding-box, border-box.
Use one per screen, and keep the glow faint on light backgrounds, where it can look muddy. Check that the text inside still has strong contrast. Sliding the strip with transform stays cheap; animating background-position repaints every frame. Under prefers-reduced-motion, keep the colors and stop the flow.
Often confused with
- Border beam
- A border beam is one short streak of light traveling around an otherwise plain edge. A gradient border colors the whole edge, and its colors may flow or stay still.
- Glow effect
- A glow is soft light around an element, with or without a border. A gradient border is the crisp colored outline itself, sometimes with a glow added underneath.
Related terms
All termsBorder beam
A short streak of light that travels around the edge of a card or button on a loop, drawing attention to it.
Glow effect
A soft halo of colored light around a button, card, or text, made with colored shadows or a blurred layer behind the element.
Animated gradient
A color gradient that slowly shifts across a surface on a loop, often used behind a hero or call to action to add warmth and motion.
Gradient text
Text filled with a color gradient instead of a solid color, made by painting a gradient background and clipping it to the shape of the letters.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.