shadcn.io is not affiliated with official shadcn/ui
The Gradient Button's fill is a gradient that slides slowly back and forth, so its colors keep moving under the label. By default it runs through violet, pink and blue under a white label, so it stands out on any theme; pass your theme's variables to colors to match it instead. On hover a soft glow of the same colors comes up under the button.
Use it for one action per page, an Upgrade or a Start trial, where a little constant movement earns attention; more than one on screen and they compete. For a ring of light around a plain button instead, use the Glow Border Button. It wraps the Button, so size works as usual. The fill is a layer twice the button's width moved by a CSS keyframe animation the install adds to your stylesheet, with no animation library, and it stands still when the system asks for reduced motion.
Installation
Usage
import { GradientButton } from "@/components/ui/gradient-button";<GradientButton>Upgrade to Pro</GradientButton>Demos
Colors
colors takes any CSS colors, start to end, including your theme's variables. Here one button moves between the primary color and a darker shade of it, and the other runs from the primary color to the destructive one, for a Go live button. The gradient slides there and back, so the list doesn't need to end where it starts.
Hover
animate="hover" keeps the gradient still until the pointer arrives or the button takes keyboard focus, and it waits where it stopped when they leave. Use it where constant motion would distract.
Duration
duration is one full shift, there and back, in milliseconds; the default is 3000. A short cycle feels lively, so keep it for small buttons; a long one, 8000 here, drifts calmly under a large hero button.
Accessibility
The gradient and the glow are decoration and hidden from assistive tech: the button is announced and activated as any Button. With animate="hover", keyboard focus starts the gradient just as hover does, and the glow comes up on focus too.
- Enter
- Activate the button.
- Space
- Activate the button.
FAQ
How do I use my brand colors?
Pass them to colors, as theme variables such as var(--primary) or any CSS color. The Colors demo builds two palettes from theme variables.
Which colors does it use by default?
Violet, pink and blue, each dark enough that the white label stays above a 4.5:1 contrast ratio. They don't follow the theme on purpose: a gray primary color would make the gradient a plain button. Pass colors to use your theme's.
Can it move only on hover?
Yes, pass animate="hover". The gradient waits where it is and moves while the button is hovered or has keyboard focus, as in the Hover demo.
Is the label readable on every part of the gradient?
The label is white with a faint shadow, and every default color keeps it above 4.5:1. If you pass your own colors, check the label against the lightest one, and set a dark label with className for light palettes.
Will a constant animation slow the page down?
No. The gradient is drawn once on a layer twice the button's width, and the keyframes only move that layer with translate, which the browser can hand to the compositor: no repaint, no re-render and no JavaScript while it runs.
Does it support variants?
size works as usual. The gradient replaces the fill, so variant changes little; it's made to be the one filled, colorful button.
API Reference
GradientButton
data-slot="gradient-button-fill"
animate?"always" | "hover"
When the gradient moves: all the time, or only while the button is hovered or has keyboard focus (it waits where it is in between).
- Type
"always" | "hover"- Default
"always"
children?ReactNode
The label, above the gradient.
colors?string[]
The CSS colors the gradient runs through, start to end; it slides
there and back, so they needn't repeat. By default violet, pink and
blue, dark enough for the white label; pass theme variables such as
var(--primary) to follow your theme.
- Default
VIVID_STOPS
duration?number
One full shift of the gradient, there and back, in milliseconds.
- Default
3000
focusableWhenDisabled?boolean
Whether the button should be focusable when disabled.
- Default
false
nativeButton?boolean
Whether the component renders a native <button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).
- Default
true
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
--gradient-button-colorsstring
The gradient's colors, comma-separated, start to end.
--gradient-button-durationstring
One shift there and back (3s).
Related
- Pro
Shimmer Button
SurfacesAmbient motion on the edge only
- Pro
Glow Border Button
Glow & lightRotating glow around the border
- Pro
Shine Button
SurfacesOne light sweep, only on hover
- Pro
Neon Button
Glow & lightGlowing halo in the primary color
- Pro
Flow Button
Glow & lightRotating border on hover
- Pro
Pill Button
SurfacesCalmer shape for a primary CTA