Removing unwanted button padding in Firefox
Recently I came across a issue with the <button> element in Firefox. It seems that if you have the following code:
<button><span>Text</span></button>
..and then apply CSS styles to set padding to zero for both the elements Firefox will automatically insert padding on the button. This is impossible to remove with standard CSS.
However there is an easy fix. Just add the following rule to your button element:
button::-moz-focus-inner {
border: 0;
padding: 0;
}
This should fix everything.
-
Got something to say?













OMG!!! Thank you thank you! I’ve been trying to fix this in FF for the past hour and was going crazy.
Why don’t I learn to just “Google It” if I havent’ fixed something in 5 minutes….?
Thanks Shane. Glad it helped you out. I spent ages looking for the solution to this too.
Google is brilliant sometimes eh?
Very helpful
The only problem with this method is that it the CSS code wont be valid anymore. Checking using the W3C CSS Validator yields the following error:
The pseudo-element ::-moz-focus-inner can’t appear here in the context css21
I’ve yet to find any workaround for this. It’s annoying.
@Syahir Hakim Thanks for pointing that out. I believe it won’t validate but personally I don’t get too hung up on the validator. However, if you’re really concerned I would put it in a separate fixes.css file along with anything else that isn’t strictly Kosher.
Thanks a lot! That was bugging me for hours. I’ve yet to fully comprehend the behavior for buttons in every (relevant) browser.
Thanks Dude - very clinical
made my day! thx man
Thank you so much, you saved my day.
Like everybody else here, i’ve been struggling with FireFox’s crazy button padding for ages, and this saved my layout!
Many Thanks!
Great fix. Thx. Any idea how to remove the padding from webkit browsers (Safari and Chrome) on Windows? The default padding is applied to these browsers in windows but not on OSX.
@Aaron
I think I might have worked out a way to fix this in Chrome with negative margin and all kinds of faff.
To be honest lately I’ve just not been putting spans inside buttons. It’s too unreliable!
If I work something out I’ll re-post. Sorry if that’s not much help at the moment…
Anyone looking to remove button padding from Webkit can try the solution at:
http://www.google.com/support/forum/p/Chrome/thread?tid=1d651b87005fa810&hl=en
This was a life saver! Thank you so much for putting this up!
THX a lot! you saved my layout!
You should be using double span as well. It solves multiple problems when trying to style tags. Example, left and right images.
Text
Also double span works across all browsers with no problems (even IE6).