The Firefox Input Button Line-Height Bug

Published February 25, 2010 by Rob Glazebrook.

I recently ran into a bug in Firefox and Opera when I tried to set the line height of text inside a button (which affects input “submit” buttons as well as the HTML button tag). The bug? The line height can’t be changed!

For example, take the following code:

input#button {
	border: 2px solid #06f;
	color: #06f;
	background-color: #6cf;
	font: bold 12px Arial, Helvetica, sans-serif;
	line-height: 50px;
}

In a perfect world, this code would be a quick and easy way to vertically center text inside a button and set the button’s height, since text is always centered inside of the space created by its line-height.

But the results are inconsistent. Chrome, Safari, and (I can’t believe this either) Internet Explorer 8 all center the text and resize the button just like I’d expect. But the results are less than perfect in Firefox and Opera (see the image above).

The Problem, Defined

A quick look at Firebug proves enlightening: even though I’ve specified a line-height of 50px, Firefox is using a line-height of 15px instead.

So what gives?

It seems our bug isn’t really a bug at all, but a “feature”: that is, it’s a deliberate decision by Firefox to limit line heights on buttons. This is evidenced by this line of CSS in Firefox’s default CSS:

button, input[type="reset"], input[type="button"], input[type="submit"] {
	line-height:normal !important;
}

Basically, Firefox is setting the line-height to “normal” on buttons and is enforcing this decision with an !important declaration. This is a frustrating decision on their part, particularly considering (as Eric Meyer has pointed out at great and detailed length), line-height: normal is anything but.

And while trying to work around this rule, I discovered something that makes the situation a little more dire: browser-defined !important rules cannot be over-ruled by author-defined !important rules. This rule cannot be overruled by a CSS file, an inline style — anything.

So what’s to be done?

After a couple of hours of teeth-gnashing, I’ve settled on the following as an acceptable workaround. Instead of using line-height, use padding.

So to take the example from earlier, we’d convert it to look like this instead:

input#button {
	border: 2px solid #06f;
	color: #06f;
	background-color: #6cf;
	font: bold 12px Arial, Helvetica, sans-serif;
	padding: 18px 6px;
}

This effectively centers the text inside our buttons, but it isn’t ideal. It means there’s no easy way to ensure our buttons are using the same line-height as the rest of our content, and it means the size of the button can’t be dependent upon the size of the button text. But I’ll take what I can get on this one.

214 Responses

  1. shower filters (reply)

    Just wish to say your article is as astounding. The
    clearness in your post is just spectacular and i could assume you are an expert on this subject.
    Fine with your permission allow me to grab your
    feed to keep updated with forthcoming post. Thanks a million and
    please continue the enjoyable work.

  2. Fitness watches 2014 (reply)

    Carli Kiene can also buy Instagram followers buy to get more followers very cheap.
    A very good thing about fake followers. In addition, this
    eight-month-old company has yet to release new solo music.
    But aside from the original Instagram and 935, 109 mentions of Instagram unapologetically expressed their dislike for the person with the user’s profile photo to life without being overly intrusive to viewers.
    Björ Blixter, a rising star out of the trailer for the download statistics in Google Play, Google’s
    new online store for digital media.

  3. Rosella (reply)

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that
    automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping
    maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy
    reading your blog and I look forward to your new updates.

  4. rakuten (reply)

    Awesome issues here. I’m very happy to see your post. Thanks so much and I’m having
    a look ahead to contact you. Will you kindly drop me a mail?

  5. Madelene Z. Ducasse (reply)

    Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is important and everything.
    However imagine if you added some great photos or video clips
    to give your posts more, “pop”! Your content is excellent but with images and videos,
    this blog could certainly be one of the very best in its niche.
    Fantastic blog!

  6. pulse drum set (reply)

    Thanks for one’s marvelous posting! I definitely enjoyed reading it, you could be a great author.
    I will make sure to bookmark youir blog and will often come back down thee road.

    I want to encourage you continue your great job, have a nice holiday weekend!

  7. Clash of Clans no survey (reply)

    The map has 3 different lanes, which lead from
    your own to the enemy base. If the ball falls in any of these slots, the player wins 8 times
    his amount. Monks invented the game hands – Jeu de Paume
    prior to tennis.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>