Gradient Buttons with CSS3
I have been having a lot of fun messing around with CSS3 and received a lot of emails since I posted my tutorial for Creating Shadows with CSS3. I decided that putting together a quick tutorial on how to use multiple CSS3 effects at the same time to create a cool looking gradient button would show people just how amazing CSS3 is.
The only draw back to using some of these effects is that they are not 100% cross browser compatible. Check out this page in the latest versions of Firefox, Safari or Chrome to really see the effects in action.
I’m going to style an anchor tag for my button so first I need to create some HTML:
<a href="#" class="button">This is my button</a> |
Now comes the fun part. Let’s start with the basic CSS necessary for our button:
a.button { border: 1px solid #ccc; padding: 10px 20px 6px; color: #999; text-decoration: none; font-size: 28px; line-height: 30px; background: #ddd; } |
Now let’s add some rounded corners:
a.button { border: 1px solid #ccc; padding: 10px 20px 6px; color: #999; text-decoration: none; font-size: 28px; line-height: 30px; background: #ddd; border-radius: 12px; -webkit-border-radius: 12px; -moz-border-radius: 12px; } |
Next comes the shadows:
a.button { border: 1px solid #ccc; padding: 10px 20px 6px; color: #999; text-decoration: none; font-size: 28px; line-height: 30px; background: #ddd; border-radius: 12px; -webkit-border-radius: 12px; -moz-border-radius: 12px; box-shadow: 1px 1px 2px rgba(0,0,0,.5); -webkit-box-shadow: 1px 1px 2px rgba(0,0,0,.5); -moz-box-shadow: 1px 1px 2px rgba(0,0,0,.5); text-shadow: #fff 0px 1px 1px; } |
And finally, the gradient:
a.button { border: 1px solid #ccc; padding: 10px 20px 6px; color: #999; text-decoration: none; font-size: 28px; line-height: 30px; background: #ddd; border-radius: 12px; -webkit-border-radius: 12px; -moz-border-radius: 12px; box-shadow: 1px 1px 2px rgba(0,0,0,.5); -webkit-box-shadow: 1px 1px 2px rgba(0,0,0,.5); -moz-box-shadow: 1px 1px 2px rgba(0,0,0,.5); text-shadow: #fff 0px 1px 1px; background: -webkit-gradient(linear, left top, left bottom, from(#eeeeee), to(#cccccc)); background: -moz-linear-gradient(top, #eeeeee, #cccccc); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#cccccc'); } |
For fun, let’s add a active effect to make the button actually look like it is being pressed when you click on it:
a:active.button { box-shadow: 0px 0px 0px rgba(0,0,0,.5); -webkit-box-shadow: 0px 0px 0px rgba(0,0,0,.5); -moz-box-shadow: 0px 0px 0px rgba(0,0,0,.5); position: relative; top: 1px; left: 1px; } |



css3 like WordPress3.0 hit the unknown possibilities of their new. Thanx so much!!!
Great tutorial! Thanks!
Great but Problem with IE8
Exactly! That is why I said to check it out in Safari, Firefox or Chrome. It doesn’t work in IE.
Lovely! but your gradient doesn’t show up on FF 3.5.9 (mac)…
Shows up in Google Chrome for mac great though! Just FYI
You should upgrade to Firefox 3.6.3.
Excellent – looking forward to better/more support for CSS3. Thanks for the tutorial.
Very nice button:) Thanks for sharing.
Seems to work in Opera as well.
Easy demo!
thanxx
grr i hate IE!!! and all the dam browsers that don’t work, just means I can’t use cool things like this until all the browsers catch up… cool tutorial though
thankx
A demo looks awesome, but seem it’s not working in IE 5.0? Could you provide any solution to use this type of CSS in older web browser version?
Hi @Bavota,
Your post’s quite amazing for me. It works well on Firefox 3.6 & Chrome. I didn’t try on IE (I got trouble with installation IE7).
Thank alot for sharing
Jimmy
Wow, nice buttons! I will integrate one of them as a search button, but with hover effect. I think it would improve the appearance.
Thank you very much!
Bye
Thomas
Cant wait to see every browser supporting CSS3 !
Internet Explorer is always the last one to do so.
There is other cool stuff about CSS3, like opacity and child for a UL list.
Thanks for the great post.