IE Hack – Hide Text on your Submit Buttons
Recently, I designed a website and I decided to do a unique style on the search field. I added a background image to the input field and then a background image to the submit button. Everything looked great until I viewed it in Internet Destroyer (Internet Explorer). That’s when the sky fell on my head…as usual.
The Issue:
I was not able to hide the text from the button, letting the underlying image to show it’s text. Normally my preferred image replacement technique is to have text in the background image and then use a negative text-indent at a high number like this:
background-image: url('my-picture-with-text.jpg');
text-indent: -9999px;
This works fine with submit buttons on most browsers, except IE.
The fix:
Add 2 extra lines to your css file:
color: transparent; text-transform: capitalize;
For some reason the text indent doesn’t work by itself in IE, so after adding these 2 lines it works. It is a hack within a hack though, the color:transparent property should work by itself, but it doesn’t. For some odd reason setting the text-transform to anything (in this case I chose capitalize because I don’t use it very often) makes it magically work. Anyhow if anyone finds this useful please leave a comment below.
**IMPORTANT UPDATE**
Thanks to a comment by Chris Mahon I learned of another (better) method for hiding text on your submits. Instead of adding color: transparent; and text-transform capitalize; (the above method) add the lines below. The above method can mess up layouts where lots of absolute positioning is happening on the page. Thanks again Chris!
background-image: url('my-picture-with-text.jpg');
line-height: 999px; /* Set it higher than your image height */
overflow: hidden; /* Hide the text */
font-size: 0; /* FF2 doesn’t like the above */


35 Responses to “ IE Hack – Hide Text on your Submit Buttons ”
February 13th, 2009 at 1:06 pm
wow! Just what I needed! Thanks.
February 25th, 2009 at 10:19 am
Nice find, this also seems to work:
==================
line-height: 999px; /* Set it higher than your image height */
overflow: hidden; /* Hide the text */
font-size: 0; /* FF2 doesn’t like the above */
==================
But your solution is neater
March 4th, 2009 at 7:24 am
Thanks for this, really useful.
March 5th, 2009 at 12:18 pm
Cool, thanks for the alternate method Chris. I am going to give it a whirl sometime soon.
May 7th, 2009 at 11:55 am
Thank you very much! I found your website through the mans best friend (google) and it did just the trick!
May 26th, 2009 at 2:15 am
[...] Source Categories: Web Development Comments (0) Trackbacks (0) Leave a comment Trackback [...]
June 2nd, 2009 at 10:43 pm
When I tried your method the submit button disappeared entirely on IE7. Has anyone else had this problem?
July 24th, 2009 at 8:37 am
I had that problem on a project and it has something to do with a property set (I think position relative) somewhere before the button in the mark up. When I had that problem I used Chris Mahon’s method above and it fixed it.
Chris Mahon Says:
February 25th, 2009 at 10:19 am edit
Nice find, this also seems to work:
==================
line-height: 999px; /* Set it higher than your image height */
overflow: hidden; /* Hide the text */
font-size: 0; /* FF2 doesn’t like the above */
==================
August 6th, 2009 at 2:58 pm
Struggling for ages with this – thanks so much
the site in question
September 1st, 2009 at 11:41 am
Many thanks indeed!
September 6th, 2009 at 10:18 pm
Hey so much thanks for this….i was in so much trouble due to this prob….thanx again
October 5th, 2009 at 8:19 am
Thanks! This worked perfectly… If only the same could be said about IE.
October 6th, 2009 at 2:43 am
Just had to swing by and say THANKS! Your suggestion plu:
line-height: 999px; /* Set it higher than your image height */
overflow: hidden; /* Hide the text */
font-size: 0; /* FF2 doesn’t like the above */
did the trick.
October 6th, 2009 at 7:23 am
this was a bit of a lifesaver. thank you.
October 21st, 2009 at 7:04 am
this seems to work for me in IE7, which is great, but not in IE6… any ideas?
October 21st, 2009 at 7:59 am
@R I had the same problem on a project, I think it was because of other things being absolutely/or relatively positioned on the page before the button. I am not sure though, IE is sometimes a quandary with it’s screw ups.
Try this as an alternate, that’s what I had to do on a project:
==================
line-height: 999px; /* Set it higher than your image height */
overflow: hidden; /* Hide the text */
font-size: 0; /* FF2 doesn’t like the above */
==================
March 5th, 2010 at 12:30 pm
Thanks issuse fixed
March 10th, 2010 at 2:55 am
Thanks, I used your first method successfully on a project, but it failed on a different project in IE7 for some unknown reason.
2nd option did the trick though!
April 27th, 2010 at 4:29 pm
Wow, magically retarded, but it works! Thanks for sharing, this was definitely a life-saver. I never would’ve figured this weird hack on my own!
May 20th, 2010 at 6:03 am
Thank you for this! Gotta love IE!
June 25th, 2010 at 3:08 am
Thanks for the solution
line-height: 999px; /* Set it higher than your image height */
overflow: hidden; /* Hide the text */
font-size: 0; /* FF2 doesn’t like the above */
It worked .
July 8th, 2010 at 7:34 am
Awesome. I never quite figured out how to handle hiding text on buttons in IE6. This worked like a charm. Thanks!
August 2nd, 2010 at 3:39 pm
color: transparent;
text-transform: capitalize;
just had joy with this in ie6, 7, and 8. seems to be one of the neatest solutions, too.
now write some code that installs google chrome frame automatically (and silently) into ie browsers
August 29th, 2010 at 8:57 am
Thanks! Couldn’t remember this one. Cheers
September 13th, 2010 at 1:35 pm
Awesome. Worked like a charm. Thanks!
November 5th, 2010 at 3:49 am
great post, worked a treat
November 29th, 2010 at 2:16 am
Thanks a bunch,
just saved me from what could’ve been half an hour pure misery.
January 11th, 2011 at 3:20 am
Thanks…! This saved me so much time.
March 4th, 2011 at 5:05 am
[...] IE Hack – Hide Text on your Submit Buttons | Amber Taylor's SharpBlog (tags: ie6 html text input buttons hack ie css tech web) [...]
March 8th, 2011 at 3:27 am
Thanks a lot…
background-image: url(‘my-picture-with-text.jpg’);
text-indent: -9999px;
color: transparent;
text-transform: capitalize;
above hack nicely working with IE..
Thanks again
May 11th, 2011 at 4:26 am
WOW. Amazing. Thanks so much. Is also can#t agree more wit you about the name Internet Destroyer. I have to test on five browsaers but that becomes eight if you have take in account that each version on IE is like a diffrent browser.
July 25th, 2011 at 8:44 pm
thanks for the post, im using it now! good thing this was on the first list on google search so i didn’t have a hard time locating for a solution! thanks to Chris Mahon too!
July 26th, 2011 at 9:07 am
Hey Bambi! No sweat, glad it helped!
December 6th, 2011 at 5:01 am
Hi,
You’ll find the following works for all browsers,
font-size: 0;
display:block;
line-height: 0;
overflow: hidden;
text-indent: -999px;
January 26th, 2012 at 6:54 am
Perfect solution, nice article. Gosh IE7, please die. :]