Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Cross Browser CSS Min-Height

15 Responses »

As you know, Internet Explorer 6 does not follow CSS' "min-height" property. Luckily, we can fix this problem using the following CSS code snippet:

#container  { min-height:500px; } * html #container { height:500px; }

Internet Explorer 6 is the only browser that recongizes the "* html _____" selector and thus is the only browser to read the hard-set height. Since IE6 also stretches down despite the hard-set height property, you can view IE6's idea of "height" as a min-height. The only drawback to using this code is that it's not valid CSS. Functionality first though, right?

Discussion

  1. August 24, 2007 @ 8:57 am

    What’s invalid about it? It relies on an invalid interpretation of the W3C DOM to work, but it looks like perfectly valid CSS to me.

  2. August 25, 2007 @ 9:37 am

    Thank you for the language correction Simon — you are correct.

  3. david
    June 13, 2008 @ 4:57 pm

    or you could do thus:

    height:auto !important;
    height:200px;
    min-height:200px;

    this would put a min-height of 2oopx on all browsers. all browsers except ie6 will respect the !important flag and ignore the second height property, while ie6 will still use the second height property, then expand as needed.

  4. kamal
    February 27, 2009 @ 1:39 pm

    Why don’t you just stop adding workarounds for IE? Rather just show a ugly red strip at the top of the page “in IE only” using its own superb conditional comments that says “please use a browser” or if it sounds rude, -> “The browser you are using is 8 years old and is unsafe! Why don’t you take a minute to upgrade to a better safer and faster browser?”

    Things like that will make them (the ignorant corporates, the technically challenged, et al) to take note. Till the day you keep giving them workarounds, they’ll keep asking for more; they’ll keep telling you “But all other sites work on my IE! Why not yours? “. “Oh well, its about time you need to know sir, that those sites work, more often than not, because some poor web designer thought it more polite to keep you in the dark about what crap you’re using!”

  5. February 27, 2009 @ 1:44 pm

    Because your client who Is paying you to make the website may be one of those tech idiots that uses ie 6.

  6. kamal
    February 27, 2009 @ 5:33 pm

    Indeed. And an attempt to educate them about their ignorance isn’t always a bad idea. Everyone can give it a try to make their own world a better place to work in! :)

  7. chandrakant
    September 4, 2009 @ 8:15 am

    Kamal is right………we designer should educate these OLD school people. This will help reduce ie 6 worldwide percentage and our life gets easier………

  8. October 29, 2009 @ 9:10 am

    I agree with Kamal.

    In the future all of my designs will display a red div layer at the top telling people to update their browser to IE 7 or 8 and recomend using Firefox.

    The rest of the website will then be displayed below and if it does not work I’m not goin to care.

  9. webcodeslinger
    December 31, 2009 @ 2:34 pm

    You guys don’t actually do work for real clients, do you?

    To say “Screw them, I’m making MY life easier by putting an ugly red message up there, and if they don’t upgrade, tough poo”, is a very irresponsible thing to do, as a web developer. There are plenty of valid reasons why a client cannot upgrade from IE6. I hate it just as much as the next person, but it’s a fact of life if you work for a company.

    I tell you what – making things work in IE6 is not hard. I don’t even think about it when I code – I just adhere to the standards and use my extensive HTML/CSS knowledge and my implementations work nearly perfectly in IE6.

    So… why don’t you just learn something and figure it out instead of being a lazy ass? Here’s a start – Google “progressive enhancement”.

  10. chandan khandelwal
    January 30, 2010 @ 1:12 am

    we can also use ,

    height: 319px;
    overflow: visible;

    height is supported by IE6 so we use height and for extra part we can use overflow: visible;

  11. April 13, 2010 @ 4:56 pm

    @ Chandan Khandelwal

    Thanks a lot! This did it for me! After searching for a solution to fix the height-problem in ie.. I can move on.. =D

  12. June 8, 2010 @ 12:53 pm

    Thanks for the tip!! I have run into this problem with some annoying clients where they are still using IE 6 and sometimes 5.

  13. July 26, 2010 @ 5:08 am

    Hello Kamal,chandrakant and Arnar
    As David had already said even though IE 6 giving web developer problem about browser compatible we shouldn’t forget about the clients and the website users . who was still using old IE 6 browser so we should keep in mind while working the project So if there is solution then why donot we use IE Hack .
    Thanks David Walsh for your min-height article.

  14. zalubom
    August 6, 2010 @ 5:56 am

    i tried all the versions in the comments, but they not worked (perfectly) for me.
    the only hack that worked perfectly is this:

    #container { min-height:500px; } * html #container { height:500px;overflow:visible;}

    • August 20, 2010 @ 1:52 pm

      Money talks!

      Given that it takes about 25% longer to do a project with IE6 then just put a surcharge for IE6 compatibility. Suddenly clients seem to care a lot less about IE6 compatibility.

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!