The design industry is probably one of the fastest growing. New and creative websites are being created every day, pushing the limitations of HTML & CSS in every direction. CSS has come a long way from formatting the structured content. It was used to control layout of documents precisely and to apply different layouts to media types.
To give designers more flexibility and interoperability, CSS3 is proposed as the next major revision of CSS. In this tutorial we will be making some cool fancy animated CSS3 buttons.
Let’s have a look what we will be creating in this tutorial.
Step 1: Start with HTML
The starting HTML is easy, we’ll crating 2 anchor tags with the class of ‘button’ and 2 classes for different color which are ‘green’, and ‘red’.
<a href="#" class="button green">Button</a> <a href="#" class="button red">Button</a>
Here is the preview:
Now we will create CSS for the HTML we wrote. This includes the shape and styling of the buttons. Following is the ‘button’ class.
.button { font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #FFFFFF; padding: 10px 75px; margin: 0 20px; text-decoration: none; }
Following are the color classes for different color buttons.
.green { border: solid 1px #3b7200; background-color: #88c72a; } .red { border: solid 1px #720000; background-color: #c72a2a; }
Here is the preview:
CSS3 styling are much advance than the normal CSS styling. Here we will add styling for advance properties of buttons like rounded corners and shadows. To obtain this we need to use various prefixes for different browsers.
.button { font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #FFFFFF; padding: 10px 75px; margin: 0 20px; text-shadow: 2px 2px 1px #595959; filter: dropshadow(color=#595959, offx=1, offy=1); text-decoration: none; }
For different button shapes (like square, rounded) we will be using different classes.
.square { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } .rounded { -webkit-border-radius: 50px; -moz-border-radius: 50px; border-radius: 50px; }
Now our HTML will look like following:
<a href="#" class="button square green">Button</a> <a href="#" class="button rounded red">Button</a>
Here is the preview:
Now we need to add the shadow styling and different CSS3 background gradient to each of the color style. You can simply make more backgrounds by changing the color in CSS.
.green { border: solid 1px #3b7200; background-color: #88c72a; background: -moz-linear-gradient(top, #88c72a 0%, #709e0e 100%); background: -webkit-linear-gradient(top, #88c72a 0%, #709e0e 100%); background: -o-linear-gradient(top, #88c72a 0%, #709e0e 100%); background: -ms-linear-gradient(top, #88c72a 0% ,#709e0e 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#709e0e', endColorstr='#709e0e',GradientType=0 ); background: linear-gradient(top, #88c72a 0% ,#709e0e 100%); -webkit-box-shadow: 0px 0px 1px #66FF00, inset 0px 0px 1px #FFFFFF; -moz-box-shadow: 0px 0px 1px #66FF00, inset 0px 0px 1px #FFFFFF; box-shadow: 0px 0px 1px #66FF00, inset 0px 0px 1px #FFFFFF; } .red { border: solid 1px #720000; background-color: #c72a2a; background: -moz-linear-gradient(top, #c72a2a 0%, #9e0e0e 100%); background: -webkit-linear-gradient(top, #c72a2a 0%, #9e0e0e 100%); background: -o-linear-gradient(top, #c72a2a 0%, #9e0e0e 100%); background: -ms-linear-gradient(top, #c72a2a 0% ,#9e0e0e 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9e0e0e', endColorstr='#9e0e0e',GradientType=0 ); background: linear-gradient(top, #c72a2a 0% ,#9e0e0e 100%); -webkit-box-shadow: 0px 0px 1px #FF3300, inset 0px 0px 1px #FFFFFF; -moz-box-shadow: 0px 0px 1px #FF3300, inset 0px 0px 1px #FFFFFF; box-shadow: 0px 0px 1px #FF3300, inset 0px 0px 1px #FFFFFF; }
Here is the preview:
For the hover and active sate we’ll edit the colors and background gradient setting for different color classes.
.green:hover { background-color: #7fb52f; background: -moz-linear-gradient(top, #7fb52f 0%, #67910b 100%); background: -webkit-linear-gradient(top, #7fb52f 0%, #67910b 100%); background: -o-linear-gradient(top, #7fb52f 0%, #67910b 100%); background: -ms-linear-gradient(top, #7fb52f 0% ,#67910b 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#67910b', endColorstr='#67910b',GradientType=0 ); background: linear-gradient(top, #7fb52f 0% ,#67910b 100%); } .green:active { background-color: #638f22; background: -moz-linear-gradient(top, #638f22 0%, #486608 100%); background: -webkit-linear-gradient(top, #638f22 0%, #486608 100%); background: -o-linear-gradient(top, #638f22 0%, #486608 100%); background: -ms-linear-gradient(top, #638f22 0% ,#486608 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#486608', endColorstr='#486608',GradientType=0 ); background: linear-gradient(top, #638f22 0% ,#486608 100%); } .red:hover { background-color: #b52f2f; background: -moz-linear-gradient(top, #b52f2f 0%, #910b0b 100%); background: -webkit-linear-gradient(top, #b52f2f 0%, #910b0b 100%); background: -o-linear-gradient(top, #b52f2f 0%, #910b0b 100%); background: -ms-linear-gradient(top, #b52f2f 0% ,#910b0b 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#910b0b', endColorstr='#910b0b',GradientType=0 ); background: linear-gradient(top, #b52f2f 0% ,#910b0b 100%); } .red:active { background-color: #8f2222; background: -moz-linear-gradient(top, #8f2222 0%, #660808 100%); background: -webkit-linear-gradient(top, #8f2222 0%, #660808 100%); background: -o-linear-gradient(top, #8f2222 0%, #660808 100%); background: -ms-linear-gradient(top, #8f2222 0% ,#660808 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#660808', endColorstr='#660808',GradientType=0 ); background: linear-gradient(top, #8f2222 0% ,#660808 100%); }
Here is the preview:
Now the fun part begins, Here we will adding styles for button effects and animation so they can change shapes. We will including few more classes for providing effects of shape change. We also add styling for hover and active state for shapes.
.effect-2 { transition: border-radius 2s; -webkit-transition: border-radius 2s; -moz-transition: border-radius 2s; -o-transition: border-radius 2s; -ms-transition: border-radius 2s; } .effect-2:hover { -webkit-border-radius: 50px; -moz-border-radius: 50px; border-radius: 50px; } .effect-3 { transition: border-radius 1s; -webkit-transition: border-radius 1s; -moz-transition: border-radius 1s; -o-transition: border-radius 1s; -ms-transition: border-radius 1s; } .effect-3:hover { border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; }
Now our HTML looks like this:
<a href="#" class="button square green effect-2">Button</a> <a href="#" class="button rounded red effect-3">Button</a>
Here is the prview:
To create more shapes (like in past we created classes for rounded and square shape) we have to add more classes for different button shapes.
.shape-1 { -webkit-border-radius: 5px 50px 5px 50px; border-radius: 5px 50px 5px 50px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 50px; -moz-border-radius-bottomleft: 50px; -moz-border-radius-bottomright: 5px; } .shape-2 { -webkit-border-radius: 50px 5px 50px 5px; border-radius: 50px 5px 50px 5px; -moz-border-radius-topleft: 50px; -moz-border-radius-topright: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 50px; }
And here is the styles for more button effects and animation.
.effect-4 { transition: border-radius 1s; -webkit-transition: border-radius 1s; -moz-transition: border-radius 1s; -o-transition: border-radius 1s; -ms-transition: border-radius 1s; } .effect-4:hover { border-radius: 50px 5px 50px 5px; -webkit-border-radius: 50px 5px 50px 5px; -moz-border-radius-topleft: 50px; -moz-border-radius-topright: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 50px; } .effect-5 { transition: border-radius 1s; -webkit-transition: border-radius 1s; -moz-transition: border-radius 1s; -o-transition: border-radius 1s; -ms-transition: border-radius 1s; } .effect-5:hover { border-radius: 5px 50px 5px 50px; -webkit-border-radius: 5px 50px 5px 50px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 50px; -moz-border-radius-bottomleft: 50px; -moz-border-radius-bottomright: 5px; }
Now change the HTML like this:
<a href="#" class="button shape-1 green effect-4">Button</a> <a href="#" class="button shape-2 red effect-5">Button</a>
Here is the preview:
Here you can see these buttons in live action. Also, you can download the source files so you can edit and directly use them in what-so-ever you like.
You can generate more animation effects by interchanging these shape classes and effect classes in HTML. Hope you like it and don’t forget to leave some feedback or review in the comments.
Hi! awesome tutorial!))
Thank U for sharing
You r Correct
Do you use Fireworks?
No, It’s clean CSS3 :)
Very informative and clear article ever i have been seen.Thanks
wow that’s a button you created.Thanks many for your great work.I like to see many button using HTML5 if possible.I also like to see php tutorial in this same web site.
Thanks for your good job.
this makes me wanna learn css in depth. awesome tutorial andres, keep’em coming :) thanx
cool..Thanks a lot
Very good tutorial, thanks. You may also find useful my blog post about button’s usability and accessibility: zinoui.com/blog/usable-and-accessible-css3-buttons
tnq nice idea for download box in my site.
this is very useful