Creating Dynamic Buttons With CSS3

Creating buttons with CSS becomes a lot more comfortable. The following example demonstrates how to create nice looking, dynamic buttons that are fully scaleable using the new CSS3 properties border-radius, box-shadow and RGBa.

CSS-Buttons

Update!

This example uses a small background gradient image to achieve the plastic look of the button. Click here for an updated version of the CSS buttons without any images at all.

The main CSS markup

.btn {
	display: inline-block;
	background: url(btn.bg.png) repeat-x 0px 0px;
	padding:5px 10px 6px 10px;
	font-weight:bold;
	text-shadow: 1px 1px 1px rgba(255,255,255,0.5);
	border:1px solid rgba(0,0,0,0.4);
	-moz-border-radius: 5px;
	-moz-box-shadow: 0px 0px 2px rgba(0,0,0,0.5);
	-webkit-border-radius: 5px;
	-webkit-box-shadow: 0px 0px 2px rgba(0,0,0,0.5);
}

By using RGBa color values, the button and text shadows always blend well with any color we’ll add to our button later on. No matter if we want the button to be green, red or blue. The code above always stays the same.

CSS3-Buttons

Using the common hex-values, we would get a result similar to the one on the right when hovering the button.

Adding the color

.blue		{background-color: #CCCCCC; color: #141414;}
.blue:hover	{background-color: #00c0ff; color: #ffffff;}

.green		{background-color: #CCCCCC; color: #141414;}
.green:hover	{background-color: #8aff00; color: #ffffff;}

.red		{background-color: #CCCCCC; color: #141414;}
.red:hover	{background-color: #ff004e; color: #ffffff;}

This is where we define the different color variations. All we need to change is the text- and background color along with the mouseover/hover values. To change the color of a button, just attach the corresponding class to the main button class.

Click here for a live demo.

78 thoughts on “Creating Dynamic Buttons With CSS3

  1. Helledge

    Very nice lesson ;)
    It’s perfect looks in FF, Safari and really bad in IE8. Will be fine if you post here fix for IE. Because some users still using this shity crap :(

  2. Henning Post author

    I know. This is because there’s almost no support for CSS3 in IE8 by now.

    To get buttons with rounded corners and / or dropshadows working in IE you still need to work with multiple background images. Although it’s not as nice & flexible as using only CSS, it is save across all browsers. Take a look at http://tr.im/LwHd for a good tutorial.

  3. Helledge

    I know this method, but i prefer pure CSS’s solutions. So, I hope Microsoft make fix for IE8 (in older versions we never see it, as other things) in future, because all new browsers support it now. Anyway thank you!
    By the way, very nice site :) And i’m waiting for new lessons!

  4. Pingback: CSS3 Buttons Without Any Images - naioo.com – Design // Dev // Inspiration

  5. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons - Speckyboy Design Magazine

  6. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons · rogdykker

  7. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates

  8. Pingback: 20 + CSS3 Tutorials and Techiques for Creating Buttons | Seventy Seven magazine

  9. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons | The New Drop

  10. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons | The New Drop

  11. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons | The New Drop

  12. Pingback: 50 Advanced CSS3 Technniques and Tutorials » DJDESIGNERLAB – Find All Your Design Inspirations From This Laboratory

  13. Pingback: Harika Css3 menu dersleri | web Design Source

  14. Pingback: 10 CSS3 Tutorials & Techniques for creating buttons. « The Creative Project

  15. Pingback: Pattern Inc » 12 Excellent CSS3 Button and Menu Techniques

  16. Pingback: 12 Excellent CSS3 Button and Menu Techniques

  17. Pingback: web design london, web designers london, london web design

  18. Pingback: 12 Excellent CSS3 Button and Menu Techniques | Web design news and tutorials

  19. Pingback: 12 Excellent CSS3 Button and Menu Techniques - Programming Blog

  20. breadwild

    Stop whining. Forget about IE. So what if it looks like crap. That’s not the developer’s fault, it’s the fault of the person using IE”Hate” (or worse). Chances are the user will never know that the buttons look cooler in other browsers. So, don’t let myopic MS hold you hostage. Design and develop for those browsers that play by the rules and the people that have the sense to use them.

  21. Pingback: 10 Simple to Follow CSS Button and Menu Tutorials | KEEMANXP.COM

  22. Pingback: 12 Excellent CSS3 Button and Menu Techniques - www.huedesigner.com

  23. Pingback: 17 CSS3 Button Styling tutorials and Techniques - Wsblogz.com – Web design magazine

  24. Pingback: CSS3 Buttons examples

  25. Pingback: 12 Excellent CSS3 Button and Menu Techniques | DESIGN

  26. Pingback: 40+ Incredible CSS3 Techniques & Tutorials | Multy Shades

  27. Pingback: 25 CSS3 Button Tutorials and Techniques | blogfreakz.com

  28. Pingback: Cool list of css3 buttons without using any images | The best Tutorials

  29. Pingback: 20 CSS3 Tutorials and Techiques for Creating Buttons | Pixelstore.us

  30. Pingback: 30 Awesome and Essential CSS3 Tutorials, Techniques and Resources to Learn

  31. Pingback: 22 Outstanding CSS3 Buttons Tutorials | Designs Mag

  32. Pingback: CSS3实例:12个优秀的按钮和菜单

  33. Pingback: 22 Essential Css3 Tutorials for Designers | Design Dim

  34. Pingback: CSS3 Button Tutorials and Techiques Revisited | Speckyboy Design Magazine

  35. Pingback: CSS3 Button Tutorials and Techiques Revisited | Programming Blog

  36. Pingback: CSS3 Button Tutorials and Techiques Revisited- rampantdesigntools.com

  37. Pingback: CSS3 Button Tutorials and Techniques Revisited | FlexLib

  38. Pingback: CSS3 Button Tutorials and Techniques Revisited | Typography Blog

  39. Pingback: CSS3 Button Tutorials and Techniques Revisited | Typography Blog

  40. Pingback: CSS3 Button Tutorials and Techniques Revisited | Programming Blog

  41. Pingback: 12 Excellent CSS3 Button and Menu Techniques | SharkWeb

  42. Pingback: 20 Excellent CSS Menu And Button Tutorials | VaneGraphics

  43. Pingback: 12 Excelentes botones y menus CSS3 | Nicomann

  44. Pingback: Beginner’s Guide to CSS3 | Technology Story

  45. Pingback: Beginner’s Guide to CSS3 | Emre Saraçoğlu's Official Blog

  46. Pingback: Beginner’s Guide to CSS3 « GFXForum.co

  47. Pingback: PandaDesignRo.com » Cool list of css3 buttons without using any images

  48. Pingback: 10 interesting CSS3 buttons tutorials

  49. Pingback: Beginner’s Guide to CSS3 | 39Articles

  50. Pingback: Excellent CSS3 Button and Menu Techniques | Techloadz.com

  51. Pingback: CSS3 Button Showcase - 25 Previews and Links to Tutorials | Hot List

  52. Pingback: Best CSS3 Tutorials Of 2010

  53. Pingback: Beginner’s Guide To CSS3 | How It's Easy (HIE) Computing community

  54. Pingback: CSS Button Tutorial | mxTutorial.com

  55. Pingback: Beautiful CSS3 Navigation and Button Tutorials | Tutsteps

  56. Pingback: Top 10 Beautiful CSS3 Button Tutorials - HTML Recipe | HTML Recipe

  57. Pingback: 24 best tutorial how to create sexy css3 buttons – CSS | Leoc magazine

  58. Pingback: Top 40 CSS3 Tutorials and Techniques for Creating Cool Css3 Buttons | Free Software, Jquery, Desiging,Template, Tech News, Artie,music,Photoshop tutorial

  59. Pingback: Blogging Well » Blog Archive » 20 CSS3 Tutorials and Techniques for Creating Buttons

  60. Pingback: 20 Tutorials and Techniques about CSS3 for Button Creation | DesDevWeb

  61. Pingback: 12 Excellent CSS3 Button and Menu Techniques | HowDoWeb

  62. Pingback: How to Create Buttons Using CSS3 Techniques - 20 Ultimate Tutorials | Smashing Buzz

  63. Pingback: 20 Excellent CSS3 buttons Techniques and Tutorials | 1step web design: Best for developer and designer

  64. Pingback: CSS gradients. Tools and examples « Pages of Htoo-Sann-Chin

  65. Pingback: 12 Excellent CSS3 Button and Menu Techniques | dhtml-menu-builder.com

  66. Pingback: 25 Excellent CSS3 Button Tutorials | codeManiac - Snippets, Templates, API and the best developer content

  67. Pingback: 12 Excellent CSS3 Button and Menu Techniques « « MegaTeacher | Let's start learning MegaTeacher | Let's start learning

  68. Pingback: 10 Awesome CSS3 Button Tutorials And Examples | DJDESIGNERLAB

  69. Pingback: 10 great CSS3 button to create tutorials and examples - Open News

  70. Pingback: 10 Awesome CSS3 Button Tutorials And Examples - Неинтересный блогНеинтересный блог

  71. Pingback: 8 Excellent CSS3 Button & Menu Tutorials | Tutsreflex

Leave a Reply