CSS Gradient Buttons: Examples and Code
CSS gradient buttons are a popular choice for modern websites because they combine two or more colours to create attractive button backgrounds. Unlike regular buttons with a single background colour, gradient buttons use smooth colour transitions to create a more interesting appearance.
You can create different gradient button styles using CSS, including linear gradients, diagonal gradients, multi-colour backgrounds and animated gradient effects.
In this guide, you’ll learn how to create CSS gradient buttons with simple HTML and CSS code. We’ll also explore different gradient styles with live previews so you can test each design and copy the code for your own website.
1. Basic CSS Gradient Button
A basic CSS gradient button uses the linear-gradient() function to blend two or more colours across its background.
You can control the direction of the gradient and choose the colours you want. This makes it easy to create buttons that match your website design.
HTML
<button class="gradient-button">Get Started</button>CSS
.gradient-button {
background: linear-gradient(90deg, #6366f1, #ec4899);
color: #ffffff;
padding: 14px 28px;
border: none;
border-radius: 8px;
cursor: pointer;
}2. Diagonal CSS Gradient Button
You can change the direction of a gradient to create different visual styles. A diagonal gradient blends colours from one corner towards the opposite corner.
Use an angle such as 135deg inside the linear-gradient() function to create this effect.
CSS
.gradient-button {
background: linear-gradient(
135deg,
#06b6d4,
#2563eb,
#7c3aed
);
color: #ffffff;
padding: 14px 28px;
border: none;
border-radius: 8px;
cursor: pointer;
}Diagonal gradients work well for modern website buttons, landing pages and creative interfaces.
3. Multi-Colour Gradient Button
A multi-colour gradient button uses three or more colours to create a richer background.
You can add multiple colour stops inside linear-gradient() and control where each colour appears.
CSS
.gradient-button {
background: linear-gradient(
90deg,
#f97316,
#ec4899,
#8b5cf6
);
color: #ffffff;
padding: 14px 28px;
border: none;
border-radius: 8px;
cursor: pointer;
}You can experiment with different colour combinations to create colourful buttons for portfolios, creative websites and promotional sections.
4. Rounded and Pill-Shaped Gradient Buttons
Gradient backgrounds can be used with different button shapes. You only need to change the border-radius property.
For a slightly rounded button, use a smaller border radius. For a fully rounded pill-shaped button, use a large value.
CSS
.gradient-button {
background: linear-gradient(90deg, #6366f1, #ec4899);
color: #ffffff;
padding: 14px 30px;
border: none;
border-radius: 50px;
cursor: pointer;
}Pill-shaped buttons are commonly used for calls to action, navigation elements and modern landing page designs.
5. Animated CSS Gradient Button
An animated gradient button changes the position of its background when someone hovers over it.
To create this effect, use a gradient with a larger background size and animate its background position using CSS transitions.
HTML
<button class="animated-gradient">
Hover to Animate
</button>CSS
.animated-gradient {
background: linear-gradient(
100deg,
#7c3aed,
#ec4899,
#f59e0b,
#7c3aed
);
background-size: 250% 100%;
background-position: 0 0;
color: #ffffff;
padding: 14px 28px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-position 0.45s ease;
}
.animated-gradient:hover {
background-position: 100% 0;
}The larger background allows the gradient to move across the button when the pointer is placed over it.
You can adjust the transition duration to make the animation faster or slower.
6. CSS Gradient Border Button
You don’t always need to apply a gradient to the entire button. You can also use a gradient border while keeping the inside background transparent or solid.
One useful technique is combining multiple background layers with background-clip.
HTML
<button class="gradient-border">
View Details
</button>CSS
.gradient-border {
background:
linear-gradient(#ffffff, #ffffff) padding-box,
linear-gradient(
110deg,
#06b6d4,
#6366f1,
#ec4899
) border-box;
border: 3px solid transparent;
color: #3730a3;
padding: 12px 26px;
border-radius: 10px;
cursor: pointer;
}The first background creates the inner button surface, while the second creates the gradient border.
You can change the inner background to match your website’s background.
7. CSS Gradient Button Hover Transition
You can combine gradient backgrounds with hover transitions to make buttons feel more interactive.
For example, you can change the gradient position, add a shadow or move the button slightly upward when someone hovers over it.
CSS
.gradient-hover {
background: linear-gradient(
90deg,
#0f766e,
#14b8a6
);
background-size: 200% 100%;
background-position: left;
color: #ffffff;
padding: 14px 28px;
border: none;
border-radius: 8px;
cursor: pointer;
transition:
background-position 0.4s ease,
transform 0.3s ease,
box-shadow 0.3s ease;
}
.gradient-hover:hover {
background-position: right;
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(15, 118, 110, 0.25);
}This creates a smooth background transition with a small lift effect.
How Do CSS Button Hover Effects Work?
CSS button hover effects use the :hover pseudo-class to change the appearance of a button when someone moves their mouse over it.
You can use it to change background colours, add shadows, move elements or create animations.
For example, here is a simple CSS button hover effect that changes the background colour.
HTML
<button class="my-button">Hover Me</button>CSS
.my-button {
background: #4f46e5;
color: #ffffff;
padding: 12px 24px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background 0.3s ease;
}
.my-button:hover {
background: #0f766e;
}In this example:
backgroundsets the original button colour.:hoverapplies a different colour when the mouse moves over the button.transitionmakes the colour change smooth.cursor: pointershows that the button is interactive.
You can use the same method to create different button animations and hover styles.
Tips for Designing Better CSS Gradient Buttons
Choose colours that work well together
Use colours that blend naturally. Colours that are too different can make the gradient look distracting. Try using two or three colours that complement each other.
Maintain good text contrast
Make sure the button text is easy to read against the gradient background. Use white or dark text depending on the brightness of the colours.
Use smooth transitions
A transition duration between 0.2 and 0.5 seconds is a useful starting point for most button hover effects. Avoid overly slow or distracting animations.
Keep button shapes consistent
Use consistent border radius, padding and text sizes across your website. This helps maintain a clean and organised interface.
Add keyboard focus styles
Hover effects should not be the only way to show that a button is interactive. Add a visible focus style for visitors using a keyboard.
Css
.gradient-button:focus-visible {
outline: 3px solid #111827;
outline-offset: 4px;
}Support reduced motion
Some visitors prefer fewer animations. You can respect their device settings using the prefers-reduced-motion media query.
CSS
@media (prefers-reduced-motion: reduce) {
.gradient-button {
transition: none;
}
} Create Custom Gradient Buttons Without Coding
The free MockupShelf CSS Button Generator makes this easier. You can customise button backgrounds, text colours, borders, shadows, hover states and animations using a visual editor.
You can also generate CSS and other code formats for your web projects.
You can also explore our guide to CSS Button Hover Effects: 20 Examples With Code for more button styles and interactive effects.
Frequently Asked Questions
Common questions about CSS Gradient buttons.
What is a CSS gradient button?
A CSS gradient button is a website button that uses a gradient background instead of a single solid colour. It blends two or more colours to create a smooth visual transition.
How do I create a gradient button in CSS?
Use the linear-gradient() function inside the CSS background property. Choose your colours and gradient direction, then apply the styles to your button element.
Can I use more than two colours in a CSS gradient button?
Yes. You can add multiple colour stops inside the linear-gradient() function to create multi-colour gradient backgrounds.
How do I create an animated gradient button?
Set a larger background-size and use the background-position property with a CSS transition. Change the background position inside the :hover selector to animate the gradient.
How do I create a gradient border button in CSS?
You can combine multiple background layers using background-clip and set a transparent border. This allows you to display a gradient border around a solid button background.
Do CSS gradient buttons work on mobile devices?
Yes. CSS gradient backgrounds work on mobile devices. However, hover effects may not behave the same way on touchscreens, so make sure the button remains clear and usable without hovering.
Note: MockupShelf.com is completely free to use, with no hidden charges or redirects. The site is supported by ads, so if you enjoy our resources, please consider disabling your ad blocker to help keep us alive.
Stay Updated
Get notified about new mockups, premium bundles, free resources, and product updates. No spam