Creating Awesome Buttons with CSS and Image Sprites
Styling your buttons can make a huge difference for your users. In user interface design, buttons should be noticeable and properly styled. You wouldn't want your users to have a hard time finding a submit or login button would you?
In this tutorial, we cover how to design a button without any javascript, or extra HTML markup. Using image sprites and some CSS, we can create some pretty awesome buttons which have three states.
Step 1
First, we need to begin by creating the image sprite that will serve as the background for the button. Open up an image editor of your choice, and create an gradient (going vertically) image of your choosing. Make this image approximately 80px high. Next create an image that is the inverse gradient (just flip it upside down) of the first. Finally combine these two images and crop the width to 10px.
Standard Gray Images

Green Button Images

Step 1.5
We need to do something else if you are interested in making a button with a point. Create an image of a button with a point. The image should have a width of at least 400px. Make three different images of both the default, hover, and pressed states, and combine them into one image.
Creating Pointed Buttons

Step 1.9
What if you want to create a button that's customizable? You can create a gradient similar to the first step, but make it light gray and transparent. Then create an inverse of that and combine the two images. Make sure to render the image as a PNG with the alpha channel on.
Step 2 - The HTML
Now that we have the images we need, lets lay down the HTML. This is relatively easy. Just add a class to an <a> tag or a <input> tag. We will be creating a class for each of the types.
Step 3 - The CSS
Now that we have added the necessary classes to our links, we need to style the buttons with CSS. Lets start with the gray buttons.
Gray Buttons
Here is the code for the gray buttons, of course you are encouraged to modify it and suit it to your own needs.
.gray-btn { display: inline-block; background: transparent url(img/btn-grey.png) repeat-x 0 0; border: 1px solid #848484; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; -khtml-border-radius: 6px; padding: 4px 6px; margin: 4px 0; color: #242424; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; text-decoration: none; font-weight: bold; font-size: 18px; text-shadow: 0 -1px #DDDDDD; line-height: 18px; cursor: pointer; letter-spacing: -1px; /* Optional- Remove if you don't like it */ } .gray-btn:hover { background: transparent url(img/btn-grey.png) repeat-x 0 -15px; /* Adjust this value accordingly, the lower it goes, the darker the hover state. Do not go past -80px */ } .gray-btn:active { background: transparent url(img/btn-grey.png) repeat-x 0 -120px; /* Adjust this value accordingly, the lower it goes, the lighter the pressed state. Do not go past -140px */ text-shadow: 0 1px #999999; outline: none; }
Green Buttons
The code for the green buttons is similar to the gray buttons. If you want to create a button of a different color, its very easy to modify this.
.green-btn { display: inline-block; background: transparent url(img/btn-green.png) repeat-x 0 0; border: 1px solid #1C3600; -moz-border-radius: 12px; -webkit-border-radius: 12px; border-radius: 12px; -khtml-border-radius: 12px; padding: 4px 8px; margin: 4px 0; color: #213E01; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; text-decoration: none; font-weight: bold; font-size: 18px; text-shadow: 0 -1px #6FD700; line-height: 18px; cursor: pointer; letter-spacing: -1px; /* Optional- Remove if you don't like it */ } .green-btn:hover { background: transparent url(img/btn-green.png) repeat-x 0 -15px; /* Adjust this value accordingly, the lower it goes, the darker the hover state. Do not go past -80px */ } .green-btn:active { background: transparent url(img/btn-green.png) repeat-x 0 -120px; /* Adjust this value accordingly, the lower it goes, the lighter the pressed state. Do not go past -140px */ text-shadow: 0 1px #64C100; outline: none; }
Pointed Buttons
The code for the pointed buttons is a bit different that than of the first two. You see, we can't simply repeat the background on the x axis as before. Instead, we position the background image to the right and add padding to the button.
.arrow-btn { display: inline-block; background: transparent url(img/btn-arrow.png) no-repeat top right; border: none; border-left: 1px solid #004D95; padding: 7px 20px 8px 8px; margin: 4px 0; color: #001D38; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; text-decoration: none; font-weight: bold; font-size: 20px; text-shadow: 0 -1px #348EE1; line-height: 20px; cursor: pointer; letter-spacing: -1px; /* Optional- Remove if you don't like it */ } .arrow-btn:hover { background: transparent url(img/btn-arrow.png) repeat-x right -35px; /* Do NOT adjust this value*/ } .arrow-btn:active { background: transparent url(img/btn-arrow.png) repeat-x right -70px; /* Do NOT adjust this value*/ text-shadow: 0 1px #00488B; outline: none; }
Customizable Buttons
When it comes to customizable buttons, we will be defining separate color classes for each style. We will create a base class, and stack more classes on those to customize our buttons.
.custom-btn-arrow { display: inline-block; background: url(img/btn-transparent-arrow.png) no-repeat top right; -moz-border-radius: 16px; -webkit-border-radius: 16px; border-radius: 16px; -khtml-border-radius: 16px; padding: 9px 40px 9px 10px; margin: 4px 0; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; text-decoration: none; font-weight: bold; font-size: 22px; line-height: 22px; cursor: pointer; letter-spacing: -1px; /* Optional- Remove if you don't like it */ } .custom-btn-arrow:active, .custom-btn-x:active { background-position: right -40px; text-shadow: none; outline: none; } .custom-btn-x { display: inline-block; background: url(img/btn-transparent-x.png) no-repeat top right; -moz-border-radius: 16px; -webkit-border-radius: 16px; border-radius: 16px; -khtml-border-radius: 16px; padding: 9px 40px 9px 10px; margin: 4px 0; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; text-decoration: none; font-weight: bold; font-size: 22px; line-height: 22px; cursor: pointer; letter-spacing: -1px; /* Optional- Remove if you don't like it */ } .left { background-position: top left; padding: 9px 12px 9px 38px; } .left:active { background-position: 0 -40px !important; outline: none; }
Now that we have defined the base styles, we need to define custom color classes for the buttons.
.green { background-color: #AEEA6F; /* Background of Button */ border: 1px solid #31540C; /* Border of Button */ color: #203806; /* Text Color of Button */ text-shadow: 0 -1px #7DCE28; /* Embed Color of the Text (text shadow) */ } .blue { background-color: #68ABE9; /* Background of Button */ border: 1px solid #284561; /* Border of Button */ color: #162736; /* Text Color of Button */ text-shadow: 0 -1px #4890D3; /* Embed Color of the Text (text shadow) */ } .red { background-color: #F75C5C; /* Background of Button */ border: 1px solid #702121; /* Border of Button */ color: #391111; /* Text Color of Button */ text-shadow: 0 -1px #C93A3A; /* Embed Color of the Text (text shadow) */ } .purple { background-color: #D741F7; /* Background of Button */ border: 1px solid #5C1B6A; /* Border of Button */ color: #391141; /* Text Color of Button */ text-shadow: 0 -1px #A936C2; /* Embed Color of the Text (text shadow) */ } .orange { background-color: #FFA133; /* Background of Button */ border: 1px solid #744814; /* Border of Button */ color: #50310C; /* Text Color of Button */ text-shadow: 0 -1px #C17720; /* Embed Color of the Text (text shadow) */ }
IE Issue
Because Internet Explorer 6/7 was made by blood sucking demon children (or something like that), it does not support the CSS rounded corners that we employ for our buttons.
Damn you Microsoft.
Show us your buttons
Of course this tutorial was meant to help you create custom buttons of your own. We insist that you take our code, modify them (do your mad scientist thing), and end up with something fantastic. Please show us your buttons and leave a comment below!
Internet Nerd, Design Freak, oh and Designmess Admin.
- 1795 reads
Sign up
Register for an account to be able to post, critique, upload designs, and much more. What are you waiting for? Join in on the fun!


















CommentsAdd your comment
offline
Member since 03/10/2010
1 post
nice resource!! sure to share my friends!!!
Post new comment