Skip to content

shadcn.io is an independent project built on shadcn/ui

Buttons

Pro

Gradient Button for Vue UI SDK

A button whose gradient fill slides back and forth, in vivid colors or your theme's. For Vue with UI SDK, when one call to action must stand out.

On this page7 sections

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.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

<script setup lang="ts">
import { GradientButton } from "@/components/ui/gradient-button";
</script>
<template>
  <GradientButton>Upgrade to Pro</GradientButton>
</template>

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.

Preview width

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.

Preview width

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.

Preview width

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.

Which way does it slide in a right-to-left layout?

The gradient is mirrored: it starts on the right and first slides the way the page reads.

What happens with reduced motion?

The gradient is shown, but it doesn't move. The glow still fades in on hover.

API Reference

GradientButton

data-slot="gradient-button-fill"

PropType
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?VNode

The label, above the gradient.

clickEffect?boolean

Apply a click effect to the button.

Default
true
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
["oklch(0.54 0.24 293)", "oklch(0.55 0.22 350)", "oklch(0.53 0.2 262)"]
debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.

Default
false
duration?number

One full shift of the gradient, there and back, in milliseconds.

Default
3000
focusableWhenDisabled?boolean

Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.

Default
false
isLoading?boolean

Show a loading indicator.

Default
false
pendingAnnouncement?string

What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.

Default
"Loading"
type?"button" | "reset" | "submit"

What a native button does in a form: "submit" submits it and "reset" resets it. Ignored when the button renders as something else.

Type
"button" | "reset" | "submit"
Default
"button"
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

EventType
@click( event: MouseEvent, details?: ButtonActionDetails ) → unknown

Runs when the button is pressed. Return a Promise to keep it pending (data-pending) until it settles. details.source says how it was pressed; a wrapper passing the click on may leave it out.

Type
( event: MouseEvent, details?: ButtonActionDetails ) → unknown
Parameters

event – React.MouseEvent<HTMLButtonElement>

details? – ButtonActionDetails

Returns
unknown
CSS variableType
--gradient-button-colorsstring

The gradient's colors, comma-separated, start to end.

--gradient-button-durationstring

One shift there and back (3s).