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.


Hello,
Thanks people for this helpful tutorial.
++++
good tutorials..god buttons.thanks.
How can i rearrange the buttons so that the are vertical rather than horizontal.
thanks Amanda
hi , veryyyyyyyyyyyyyyyyyyyy goooooood site
I Love u
woooww… thats realy cooooll! thx
Hey, this is probably the best CSS3 button tutorial I’ve seen in a while. Good work!
Thanks – works, nicely designed tutorial. I respekt the work. Just great!
Very nice buttons, although in IE9 the gradient goes right up to the corners yet there is a rounded border radius inside of that which looks a little untidy…. i’m trying to fix it, any ideas ?
Me too, looks ok with the colours I’m using but would be ideal to get them rounded!
Wonderful, thank you. Looks great in Firefox, in Chrome and IE, don’t care about gradient or corners, just have to get the text fitting in the “Add to Cart” buttons, don’t know how that got so wonky.
Working on site here – http://spottedsheepyarnshoppe.com/zencart
Hi Tammy
Just been to your site to see your buttons and was impressed :-)
How do you get that lovely central bit that separates from the background?
I’d love to do that to some of my pages [just learning web design]
Many thanks
Nice example on creating a very catchy CSS 3 button. I was working on a project and needed something cool to make it stand out and your examples here have definitely saved the day.
Great job.
A very good tutorial. Another thing to note, if anyone is interested, is that you can add multiple box-shadow’s. You can use the inset feature to give a good internal shadow, or give your buttons a bevel effect. Something like this:
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2),inset 1px 1px 1px rgba(255,255,255,.3);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2),inset 1px 1px 1px rgba(255,255,255,.3);
box-shadow: 0 1px 2px rgba(0,0,0,.2),inset 1px 1px 1px rgba(255,255,255,.3);
And regarding the IE gradient, it overlaps the border radius. So definitely impractical to use on elements with rounded borders. Maybe there’s a fix somwhere :D
Hi, Can I use this code to use as an input button for a form?
If so, How would I add this to the code below.
Thanks
Excellent tutorial! Thanks a bunch! I am going to be using these buttons in my company’s website!
Good tutorial!
thank you. 고마워요~
is there a way to embed a picture inside the button instead of text?
Nice. thank you.
nice! very useful, thanks
Thanks a lot for your CSS buttons!
Thank you very much for your teaching material, is very useful to me really appreciate it
Thank you very much for the awesome tutorial!