Last week I talked about Cross-Browser CSS Gradient. Today I'm going to show you how to put the CSS gradient feature in a good practical use. Check out my demo to see a set of gradient buttons that I have created with just CSS (no image or Javascript). The buttons are scalable based on the font-size. The button size can be easily adjusted by changing the padding and font-size values. The best part about this method is it can be applied to any HTML element such as div, span, p, a, button, input, etc.
What Is So Cool About These Buttons?
- Pure CSS: no image or Javascript is used.
- The gradient is cross-browser supported (IE, Firefox 3.6, Chrome, and Safari).
- Flexible and scalable: button size and rounded corners can be adjusted by changing the font size and padding values.
- It has three button states: normal, hover, and active.
- It can be applied to any HTML element: a, input, button, span, div, p, h3, etc.
- Fallback: if CSS3 is not supported, it will display a regular button (no gradient and shadow).
Preview
The image below shows how the button will display in different browsers.

Button States
- normal state = gradient with border and shadow styles.
- hover = darker gradient
- active = gradient is reversed, 1px down, and darker font color as well.

General Styles For The Button
The following code is the general styles for the .button class. I use em value in the padding and border-radius property to make it scalable base on the font-size. To adjust the rounded corners and button size, simply change the border-radius, font-size and padding values. For example: I can make a smaller button by decreasing the font-size and padding values (see demo).
For more details on border-radius, text-shadow, and box-shadow, read my article The Basics of CSS3.
.button {
display: inline-block;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 14px/100% Arial, Helvetica, sans-serif;
padding: .5em 2em .55em;
text-shadow: 0 1px 1px rgba(0,0,0,.3);
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .5em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.button:hover {
text-decoration: none;
}
.button:active {
position: relative;
top: 1px;
}

Color Gradient Styles
The code below is the CSS styling for the orange button. The first background line is a fallback for the non-CSS3 browsers, the second line is for Webkit browsers, the third line is for Firefox, and the last line is a gradient filter that is only read by Internet Explorer.
For more details on CSS gradient, read my article Cross-Browser CSS Gradient.
.orange {
color: #fef4e9;
border: solid 1px #da7c0c;
background: #f78d1d;
background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
background: -moz-linear-gradient(top, #faa51a, #f47a20);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
}
.orange:hover {
background: #f47c20;
background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
background: -moz-linear-gradient(top, #f88e11, #f06015);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
}
.orange:active {
color: #fcd3a5;
background: -webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a));
background: -moz-linear-gradient(top, #f47a20, #faa51a);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f47a20', endColorstr='#faa51a');
}

How To Use My Buttons?
Lets say you like the blue button and want to use it on your page:
- First, copy the .button and .blue CSS (view demo source code).
- Then, add class="button blue" to the HTML element where you want the button to be (eg.
<a href="#" class="button blue">Button</a>). The CSS classes can be applied to any element such as link, p, span, div, input, button, etc.


Hi all,
Love the buttons, but as stated unfortunately IE9 is played up. For anyone who’s interested, I added this in the .button class to remove the corners for IE – at least you don’t end up with dodgy corners.
border-radius: .5em;
<!–
Urgh, that didn’t format right.
Replace # with !.
border-radius: .5em;<#–
LOL, that doesn’t output either!
Last attempt, otherwise just delete the comments.
Reaplce LB with and # with !.
LB#–[if #IE]RBLB#–RBborder-radius: .5em;LB#–LB#[endif]–RB
And then he handed you the thirty-five 45
nice sense of humor :)
See my comment below for a quick and [ridiculously] easy fix for IE9.
Screw it, just use the if !IE syntax in CSS and remove the border-radius in the .button class.
Thx. The information is very interesting. Can be used practically.
Hey there! I know you posted this over a year ago, but wow wow wow! I have been trying to update the various “button” type elements on our website and the amount of CSS I used was atrocious. Not to mention in Internet Exploder it looked like just a text link with space around it. Thank you for this post!
Oh, and I’m thoroughly impressed. At least two (2) posts on each page of your blog has something I can use. You rock!
Nice post. It’s really help me.
Thx :D
Hello really Good Work am get & unique idea Your Best Tutorials Thx and GOD BLESS YOU Get Complete Tutorials
on my website SEO Tips & web design Tips in Photoshop
Hey Now;
Great post on CSS3 button styles.
Thx 4 the info;
Catto
thanks much, I’ve been scouring the web for three days and had a few usable but clumsy solutions. This is great stuff, gonna make me look like I know what I am doing. Too many tutorials show things that don’t work that well or that you need to spend a lot of time refining. This works great right out of the box. thanks!
I’m doing some buttons and wanted them to have a gradient background, and found your post really useful so thanks
As for good programming.
Awesome man… good job
You can support even more browsers if you add their vendor-specific gradients:
background: -webkit-gradient(linear, left top, left bottom, from(#444), to(#000));
background: -webkit-linear-gradient(top, #444, #000);
background: -moz-linear-gradient(top, #444, #000);
background: -ms-linear-gradient(top, #444, #000);
background: -o-linear-gradient(top, #444, #000);
background: linear-gradient(top, #444, #000);
Also do NOT use RGBA() with text-shadow – unless you want your elements to look hideous in Chrome… just use a hex code for text-shadow instead.
i got to you blog a project late, but still best thing i have see, just copy and past stuff no need to do any thing with out images. thanks a lot for sharing
IMPORTANT: I just made this discovery last week, but if you put a space (yes, a space) AFTER “progid:” you will get beautiful buttons in IE9 as well!!!
filter: progid: DXImageTransform[...]
Cheers
Unfortunately your just voiding the gradient and it’s falling back to the solid color… so your still not getting both border radius and background gradient.
I definitely misspoke in this comment – my apologies to everyone in this thread – I should have come back and corrected myself once I discovered my error. You cannot use rounded corners and background gradients in IE9. You can sometimes use an inset shadow to achieve a similar effect.
It’s cool man :)
How to increase the size of buttons?
Thanks I always find this website helpful, whenever I get stuck in designing process.
i liked all the buttons here they look so nice and clean. thanx
@Ryan Wheale – Great find. IE9 works perfectly now.
Unfortunately, it appears to work on small buttons, but you will notice that the entire gradient gets defeated. Try doing it on a large DIV… you will see that there is no gradient at all.
The rule of thumb I now live by is to not use filter: progid:… with rounded corners… ever. Sometimes I will use an inset shadow to give the effect I am after.
So sad that IE9 supports background gradients and rounded corners… but not both :(