Styling HTML Submit Buttons
Lately I have been coding few website including many HTML forms and I found out that various browsers will render HTML submit button quite differently. I will show you how to properly style submit buttons in order to achieve a very similar look in all major browsers. First, bellow is a basic HTML submit button markup.
<input type="submit" name="submit" value="Submit" class="submit" />
First thing I did was to set a small padding on sides of the button to make it look better, leaving a default browser button look. I have also changed the default cursor when pointing on a submit button. Bellow is the corresponding part of the stylesheet.
.submit {
cursor:pointer;
padding:1px 5px;
}
Here is how our HTML submit button looks in different browsers so far (all used browsers were clean installations without any widgets, plugins or add-ons):

As you can see, Firefox 3.0 and Opera 9.5 render the button pretty good, Internet Explorer 7 does not. IE7 adds too much padding to the left and right side, making the submit button look ugly. It’s a well-known IE width bug (present in both IE6 and IE7), easy to fix though. Let’s edit the stylesheet.
.submit {
cursor:pointer;
overflow:visible; /* ie6/7 width fix */
width:auto; /* ie6/7 width fix */
padding:1px 5px;
}

Looks much better now. Next thing I wanted to do was to achieve exactly the same look in all three browsers. Let’s add some border and background color.
.submit {
cursor:pointer;
overflow:visible; /* ie6/7 width fix */
width:auto; /* ie6/7 width fix */
padding:1px 5px;
background:#ddd;
border:1px solid #aaa;
}

As you can see, our HTML submit button is already looking fairly similar in all three browsers. Finally, let’s define a color and font for the submit button value.
.submit {
cursor:pointer;
overflow:visible; /* ie6/7 width fix */
width:auto; /* ie6/7 width fix */
padding:1px 5px;
background:#ddd;
color:#333;
font:10pt arial, sans-serif;
border:1px solid #aaa;
}

That’s it. Probably the closest look possible to achieve. They are still not the same though. Especially the one in IE, which has too much top and bottom padding. I haven’t yet figured how to fix that. Once I figure it out, I will update this post. If it really bothers you, you can still use Internet Explorer conditional comments and reset the padding just for Internet Explorer.
July 11th, 2008 at 9:33 pm
Well another approach would be to use the button element instead of just input
<button type="submit">Submit</button>this way you can style it individually & get it to look 100% across all browsers, you can also go as far as having an image in there etc. (button) is way more flexible.
July 12th, 2008 at 6:54 pm
Yep. I have totally forgot about that approach. Thanks for the tip.
July 31st, 2008 at 5:52 pm
I only recently started styleing my forms and I have been looking for cross browser button codes, thanks for the post and thanks for the tip greg.
August 1st, 2008 at 10:23 pm
govind221817@gmail.com
October 5th, 2008 at 12:19 am
The IE width issue was one I have been trying to solve for a while now.
Thank you for providing the solution!
March 10th, 2009 at 10:58 pm
Styling buttons using CSS is good and can achieve professional results. However in my experience, using image as the form button provides many more possibilities and can lead to design of creative buttons that cannot be easily achieved by styling standard form buttons.
May 28th, 2009 at 2:12 pm
@Web design Company, using an image is nice but doesn’t work well for dynamic and site-wide styling of input buttons.
@author, thanks for the tips!
July 17th, 2009 at 11:19 am
@web design company, I am totally agree with you. I always design new HTML submit buttons because is more attractive to my visitors. thank you for the posting.
August 6th, 2009 at 11:39 pm
Buttons are great and can achieve professional outcome. In my past experience using image as theprovides many more possibilities and can lead to lots of creative buttons that cannot be easily achieved by styling standard HTML.