Create a Sleek CSS3 Button Under a Minute

By | August 13, 2015

As a web developer we often find ourselves creating buttons for submit buttons, links and more. Doing this the old fashioned way can take a lot of time as you need to open photoshop and create that gradient background, shadow effects etc.
In this tutorial I’m going to show you how to create a very sleek web 2.0 CSS3 button in under a minute.

Getting Started

We’re going to start by creating the button in basic CSS.

01 border: 1px solid #5d9046;
02 background: #67AA25;
03 color: #fff;
04 text-transform: uppercase;
05 font-family: Arial, Helvetica, Sans-Serif;
06 text-decoration: none;
07 width: 156px;
08 font-size: 14px;
09 font-weight: bold;
10 padding: 8px 0;
11 text-align: center;
12 display: block;

This is going to give us a very simple square button as illustrated below:

Pretty boring huh? Let’s style it up a little bit 😀

Creating Rounded Corners

Now that we’ve created the basic button, we can create rounded corners easily thanks to CSS3.
Simply add the following code into your button class to create the rounded corners.

1 border-radius: 4px;
2 -moz-border-radius: 4px;
3 -webkit-border-radius: 4px;

Now our button looks like this:

Adding Shadows

Thanks to CSS3 you can easily add shadows to your boxes or text. I’ve pasted some code below to give your button even more style:

1 text-shadow: 1px 1px 1px #666;
2 -moz-box-shadow: 0 1px 3px #111;
3 -webkit-box-shadow: 0 1px 3px #111;
4 box-shadow: 0 1px 3px #111;

This code adds shadow to our text, and to our buttons. Neat huh?

Creating a Gradient Background for our Button

Thanks to an awesome application created recently by the creators of ColorZilla, we can now easily create gradients using css3 without having to use images.
Link: Gradient Editor

Using the gradient editor, I’ve created my background and the editor compiled the following code for me to use:

1 background: #3F8EB5; /* old browsers */
2 background: -moz-linear-gradient(top, #3F8EB5 0%, #1D76A0 100%); /* firefox */
3 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3F8EB5), color-stop(100%,#1D76A0)); /* webkit */
4 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3F8EB5', endColorstr='#1D76A0',GradientType=0 ); /* ie */

It falls back wonderfully so you don’t have to worry about older browsers not seeing your button etc.
Below you can see the end result of our button:

Now you can go ahead and add :hover and :active pseudo-classes to bring the button even more to life.

I hope you guys enjoyed this tutorial!
Feel free to leave comments below

Leave a Reply

Your email address will not be published. Required fields are marked *