CSS Gradient Button — Hover Effects, Border & Animated Examples
Updated: May 2026
Gradient buttons elevate call-to-action elements from flat rectangles to polished, tactile components. CSS makes it easy to add subtle hover lifts, gradient borders and color-shift animations — all without a single image file.
Free · No upload · In your browser
Live demos — hover to interact
Basic gradient button
The hover lift is achieved by combining a small translateY(-2px) with a matching drop shadow. The shadow color should match the dominant hue of the gradient — use its RGB values with a 0.3–0.5 alpha.
Gradient border button
CSS cannot apply a gradient directly to border-color. The standard technique uses a pseudo-element:
The background-clip: padding-box stops the button's own background from bleeding into the border zone. The ::before pseudo-element sits behind the button (z-index: -1) and its gradient shows through the transparent border area.
This pseudo-element trick requires the button's parent to have a defined background so the z-index: -1 layer does not disappear behind a transparent parent.
Hover color-shift animation
Since CSS cannot transition between two gradient values, animate the background-position over an oversized gradient:
The gradient is 300% wide. Moving the position from 0% to 100% on hover sweeps the visible window across the gradient, creating a smooth hue shift. The transition on background-position is fully supported in all modern browsers.
Press / active state
An active state provides tactile feedback when the button is clicked:
The upward movement from hover is reversed slightly on click, mimicking a physical press. This small detail significantly improves perceived quality.
Accessibility checklist
- Ensure sufficient contrast between the button text (
color: #fff) and both ends of the gradient. Both colors must pass WCAG AA (4.5:1 ratio for normal text). - Keep a visible focus ring: override
outlinewith a custom style rather than removing it. A gradient glow viabox-shadowon:focus-visibleis a common pattern. - Do not rely on color alone to communicate state — the hover lift and shadow convey the interactive nature alongside the gradient.
Frequently asked questions
Can I transition a CSS gradient on hover?
Not directly — CSS cannot interpolate between two gradient values. The two main workarounds are: animating background-position on an oversized gradient, or using the CSS @property at-rule to register and transition individual color stop values as custom properties in modern Chromium and Firefox.
How do I apply a gradient to a button border?
Use a pseudo-element positioned absolutely behind the button with z-index: -1, sized to the button plus the border width on each side using inset: -2px. Set the gradient as the pseudo-element's background. The button must have background-clip: padding-box and a transparent border to reveal it.
Why does my gradient button look flat on mobile?
Mobile screens typically render at higher pixel density. A gradient that looks rich on desktop may appear washed out if the colors are too close in lightness. Add a slight opacity or brightness difference between stops — at least 15–20% lightness change — to ensure the gradient remains visible at small sizes.