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,
Anyhow it is not working on IE9 as IE9 does not support gradient effect and border-radius properties at the same time!
I am working on this issue. I will get back to you if I found something.
regards,
Siddhesh
Hi Siddhesh,
Do you have a solution for IE9?
Greetz,
Jeroen
The solution was alreadey in the comments:
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
Putting that space in gets rid of the gradient. You could take out the filter completely and get the same effect.
What a dumbo Jeroen is! LOL
awesome.. Thank for the tutorial.
Hi, thanks for the code.
Just created a plugin for wordpress to add your css buttons to wordpress websites. Need your mail to send you the zip file.
cheers,
serge
Nice and good
For the color part I added the W3C-Version (linear-gradient), Opera-, MS-, and webkit-gradient-browser-prefixes using the “Ultimate CSS Gradient Generator”: http://www.colorzilla.com/gradient-editor/
thank you again. your example is very easy and so beatiful.
These are awesome! Thanks!
Thanks for this information! At the same time I searched for this, I also came across CSS Pie (http://css3pie.com/) which addresses the extra features for Internet Explorer. I think I will try your solution first though, because I like understanding what goes on underneath. (And thanks for the people in the comments for pointing out the IE9 fix).
“
thanks for the tip, I was looking for it since far !
Exactly what I was looking for! Thanks!
Hi, I know you answered some questions about the IE problem, but I still cannot get this to work on IE. I am quite a newbie about CSS, so if you excuse my maybe silly question: I added the space like this: filter:progid: DXImageTransform.Microsoft.gradient(startColorstr=’#ed1c24′, endColorstr=’#aa1317′);
But IE still doesn;t show the color of the button, it’s just rectangular and white
Very well done, going into my web-tools bookmark folder for sure. Thanks.
Great Stuff! Thanks so much as I was having problems with CSS3 buttons in IE8, but this fixed it. However, I did have a question as I’m a newbie to all this stuff. I have a lightbox that pops out once a button is clicked. Here’s the code using my previous button: Button
I can’t get the lightbox to work with this button’s code because it uses the “class=” as well. Is there a work around or simple line of code that I’m missing? Any help would be appreciated!
as I said, I’m a newbie and put complete code into the post, but I’ll give it one more shot:
a target=”_blank” href=”https://clc.ccbchurch.com/w_form_response.php?form_id=24&tab=nw&lightbox[iframe]=true&lightbox[width]=770&lightbox[height]=760″ class=”lightbox”>Online Connection Card</a
definitely, a BIG BIG deals.thx, for article
Hi! i’m using thesis theme and i don’t know where to put the code you gave is it for custom.css? please reply!
Hi Nick,
Love the buttons! I have a question: given a base color, how do you get the rest of the colors (border-color, gradient colors, etc)? Are the rest of the colors the base color with the brightness changed?
-Venkat
these are really good by Anas Ali
web designer at
Ahead
Creations web designing company in delhi India
I am Software developer.
freelance web designer and developer from Malaysia | cheap Web Designing.Offers bunch of creative services – custom web design (layout, applications, CMS, CSS), e-commerce, graphic design, creative copywriting, corporate identity, logo design,interactive marketing and more…
Hi,
I have a question i have the code but when i put it into my css how do i name it so i can link it to a div in html.
Like normally i would do for example in my css — “#navagation { (and then the code);}”
and i would link it to my html code like for example–” “
Hi,
I Really like this code! :) but
I have a question i have the code but when i put it into my css how do i name it so i can link it to a div in html.
Like normally i would do for example in my css — “#navagation { (and then the code);}”
and i would link it to my html code like for example–” “