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.


anyone has idea why:
input element in Opera 10.51
dosent work?
it hasent got text drop-shadow
its strange since other button work quite well…
Nice tutorial, the code is clear and easy to understand. Thank you very much for sharing, I’ll use it in my website right now.
What a great post! CSS3 is so neat. Thanks for this!
This is very nice.
While I don’t agree with using Microsoft filters to ape CSS3, you have omitted the declarations for IE8, e.g.:
-ms-filter: “progid:DXImageTransform.Microsoft.gradient(startColorstr=’#faa51a’, endColorstr=’#f47a20′)”;
Super cool CSS3 gradient buttons. :)
Good stuff.. I’m starting to think pretty soon we won’t need PS any more :)
nice buttons
The technique is great, and you made it really easy to understand and use,
but what really amazed me was your wonderful choice of colors.
I don’t think a tutorial can be made any better than what you’ve done here!
Keep up the good work.
Mamdouh
Thanks for this, I’ll definitely try it out on my site!
Simple and neat!
Thanks for putting together!
wow nice sharing btw which IE version supports it???
Really cute! I’m planning in making my own website and this buttons is perfect! thanks a lot!
This is really cool, I’ll have to book mark it for the next time I’m working on web buttons.
Great Stuff!
Should maybe add :focus along with :hover and :active
This is very cool indeed, nice way to have more styled up basic buttons on a site without using images — but it’s still very annoying you have to use all the browser specific code. :(
This + ie-css3.htc and you’ve got complete coverage!
This is great!
Thanks!
I also agree that this technique is great, and you made it really easy to understand. This is a brilliant tutorial, keeping it simple by using no image or Javascript, and simply using CSS. The gradient adds a nice pop to a simple button, to add a different look to spice up your web design. The button states make it completely user friendly with the hover and active shades. The way you broke it down is brilliant for those just starting out
what a great idea. Im looking for some cool ideas to put on my website.
Very cool, thanks for the great detailed examples.