How To Design A Sexy Button Using CSS
Last week I launched a holding page for Ecliptic Labs, an iPhone development company based in Belfast (keep an eye on them, there’s going to be some great stuff from them this year).
Here is the holding page in all it’s glory.
One thing you’ll notice is the big ‘Notify me’ button. One of the great things about this button is that it isn’t a graphic. It’s simply styled using CSS.
Advantages of using CSS instead of a graphic:
- Optimisation – less file size, less http requests
- Reusable – button can be used over and over again for different actions
- Flexible – the button can stretch or compact depending on length of the text
Styling the button element
I’m going to be using Firefox 3.6 for the previews below.
The markup
<button>Notify me</button>This is how the default button looks.

Basic styling
First apply some basic styling to get started.
button{
color:#08233e;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
padding:14px;
}Nothing strange or startling about these styles. This is what we have now.

Background
Let’s add a background. Remember, we want to make the button reusable for any colour.
- Go into Photoshop and create a new image 10px x 100px
- Create a white rectangular shape that covers the top half of the canvas on a new layer
- Give that layer 30% opacity and make the background transparent
- Save that image as overlay.png

Decide what background colour you want to use and apply it to the button along with the overlay you just made.
background:url(overlay.png) repeat-x center #ffcc00;This gives us a nice yellow background with a glossy overlay.

Border
Now get rid of that horrible outset border. Let’s give it a fine border that matches the background colour.
border:1px solid #ffcc00;
Rounded corners
Make your button a bit friendlier by giving it rounded corners. This is where Webkit and Mozilla browser users will take advantage, while IE browsers will be stuck with sharp corners.
-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;
Starting to look good eh? But a good designer likes to pay attention to detail.
Pixel perfection
Now finish off the button with some pixel perfect embossing. We’re going to give it a 1 pixel border and a 1 pixel inset shadow.
border-bottom:1px solid #9f9f9f;
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);Notice how we’re using RGBA colours here. This allows us to apply alpha opacity to the colour. In this case, we’re giving white a 50% opacity.


Make it clickable
We know it’s a button and that it can be clicked but users might not. Change the cursor to a pointer so users know they can click it.
cursor:pointer;Hover state
We now have a pretty sexy looking button. But what about a hover state?
To save us from thinking about a colour for the hover state, we can use the RGBA approach. Let’s revisit the background style. Add this after your background declaration.
background-color:rgba(255,204,0,1);Nothing changes. All we did was change it to the same colour but using RGBA.
But how for the button’s hover state, give it the same background colour but alter the opacity slightly.
button:hover{background-color:rgba(255,204,0,0.8);}This gives us a slightly different shade of background on hover, giving the user some feedback so they know they’ve hovered over a clickable button.
Put it all together
The final code.
button{
color:#08233e;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
padding:14px;
background:url(overlay.png) repeat-x center #ffcc00;background-color:rgba(255,204,0,1);
border:1px solid #ffcc00;
-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;
border-bottom:1px solid #9f9f9f;
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
cursor:pointer;
}
button:hover{background-color:rgba(255,204,0,0.8);}
button:active{position:relative;top:2px;}I’ve slipped in an active state as well for the button so the user knows when they’ve clicked it.
This is how it looks in Firefox:

And this is an active preview.
Remember the button is reusable so if you apply a class to the button, e.g. class=”save”, you can apply a different colour to this button.
button.save{
background-color:#a7dd32;background-color:rgba(167,221,50,1);
border-color:#a7dd32;
}
button.save:hover{
background-color:rgba(167,221,50,0.8);
}And you’d get something like this.

But what about Internet Explorer?
Yes, unfortunately IE users won’t get the full benefits of the sexy button. However, it doesn’t look that bad and to IE users it will seem like there is nothing wrong.

And IE6? It doesn’t support PNG transparency so you can remove the overlay background image with an IE6 conditional stylesheet.
<!--[if lt IE 7]>
<link rel="stylesheet" href="ie.css" type="text/css" />
<![endif]-->Then in ie.css:
button{background-image:none !important;}And there you have it. A beautifully designed button using (pretty much) only CSS.
Further reading
I highly recommend you check out this great tutorial by Zurb on super awesome buttons with CSS3 and RGBA. A handy tutorial for styling reusable buttons.
Related articles
25 Appreciated Comments
Have a comment? Tweet @leemunroe and I'll be glad to respond.


On the , Peter said:
At first I was interested in how you did this. Then I noticed you are still using an image to create this button. This then raises the question; why not make the button itself round directly in Photoshop instead of using non-validating CSS tags which aren’t even supported by one of the biggest browsers?
Except for the rgba hover part, this isn’t really exciting and the title is kind of misleading.
On the , Avangelist said:
Actually Peter, they are validating tags, they conform to the W3C guidelines for CSS3. The advantage of this over photoshop is that photoshop means you have a graphic that may require updating. In a commercial environment, this costs money. A designer has to build a new button set, and you have to update each instance of the relevant file.
By using CSS, if the colour states need changing, it is a single task from the UI developer to update the CSS file and it is site wide.
It also reduces loading time, requests to the server and ensures that the site is future proofed. This will be accepted across all browsers in the very near future, and until then, you provide alternative experiences for alternative browsers.
On the , wd said:
Indeed, i was hoping for cross-browser solution too.
And since you are using separate CSS for IE you could enable PNG transparency instead of removing it by using filters:
http://christopherschmitt.com/2007/10/30/png-transparency-for-internet-explorer-ie6-and-beyond/
On the , Peter said:
@Avangelist; ok, now I understand the practicality in it. Thanks for clearing that up. Maybe Lee should mention these advantages in his post.
On the , Chris said:
Love the button ;)
Where available what about a bit of webkit/moz gradients to do the gloss e.g.
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.0, rgba(255,255,255,0.4)),color-stop(0.5, rgba(255,255,255,0.4)), color-stop(0.5, transparent));
background-image: -moz-linear-gradient(
top, rgba(255,255,255,0.4) 50%, rgba(255,255,255,0.0) 50%
);
On the , Samantha Miller said:
Surely this is how to build a sexy button, not design?
On the , Lee said:
@Peter: Yes I’ve highlighted a few advantages at the start (optimisation, reusable, flexible). It depends on your feelings towards IE and support of CSS. I’m all for pushing CSS3 and standards forward, as long as it degrades gracefully for nonsupporting browsers.
@Avangelist: Thanks for the comment – you hit the nail on the head :-)
@wd: By all means use a png fix. I’ve always had trouble with png background fixes (I know there are lots out there) and have got to the point where I just remove the png.
@Chris: Even better. Make use of CSS gradients. Nice touch.
On the , Muxx said:
Now THIS is amazing!
Thank you for an awesome tutorial. I hate having to use images for so many buttons on a page, it really starts to add up on the load time and server requests.
The more I can accomplish using coding, the better.
On the , B2B web design said:
great design for CSS button. I’ve tried some before but your list seems better
On the , Pali Madra said:
Great tutorial. Thanks. This is the most easy to follow and precise tutorial.
One n00b question. Why did you shift to the RGB mode? Is it because of the effect that is being created?
Thanks in advance.
On the , Toufeeq said:
Thanks a Lot bud. That was superb and I couldn’t wait to add them on my blog …. :)
On the , prakash patidar said:
Thanks, a lot i use tutorial and easy to make sexy button for my website…………..
On the , mebutbetter said:
Thanks for the tutorial, working through it now.
On the , Steven said:
Hi, I read your article. To do this trick for IE7 and IE8 u can use pie, http://css3pie.com/. Works beautiful.
On the , Dave said:
i may have missed something, but you originally created the image “overlay.png” to provide the gloss effect, yet in your final code you refer to “button.png”
…
background:url(images/splash/button.png) repeat-x center #ffcc00;
…
shouldn’t overlay.png be referenced instead of button.png ?
picky, but for newbies may be confusing.
On the , Lee said:
@Dave: Well spotted, I can see why that would be confusing. Have updated the code.
On the , Aj Banda said:
Thanks for this wonderful suggestion, it really works nicely on my project
On the , Mikel said:
I dont like using images since all can be done in just css3 but.. this is nice :D :D