9 Most Common IE Bugs and How to Fix Them

9 Most Common IE Bugs and How to Fix Them

Internet Explorer – the bane of most web developers’ existence. Up to 60% of your development can be wasted just trying to squash out IE specific bugs which isn’t really a productive use of your time. In this tutorial, you are going to learn about the most common IE bugs and rendering disparities and how to easily squash them or deal with them. Interested? Let’s get started.


1. Centering a Layout

Centering an element is probably something every web developer has to do while creating a layout. The easiest and most versatile way to center an element is to just add margin: auto; to the relevant element. The above method will take care of centering the element irrespective of the resolution and/or browser width. IE 6 in quirks mode however decides to handle this in the most unfortunate way possible: by not handling it at all.

Consider the Following Code:

#container{
	border: solid 1px #000;
	background: #777;
	width: 400px;
	height: 160px;
	margin: 30px 0 0 30px;
}

#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 100px;
	margin: 30px auto;
	
}

The output you’d expect:

Tutorial Image

But what IE actually gives you:

Tutorial Image

This is mainly due to IE6 in quirks mode and below not recognizing the auto value we set to the margin property. Fortunately, this is easily fixed.

The Fix

The easiest and most reliable way to center content for IE6 and below is to apply text-align: center to the parent element and then apply text-align: left to the element to be centered to make sure the text within it is aligned properly.

#container{
	border: solid 1px #000;
	background: #777;
	width: 400px;
	height: 160px;
	margin: 30px 0 0 30px;
	text-align: center;
}

#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 100px;
	margin: 30px 0;
    	text-align: left;
	
}

2. Staircase Effect

Almost every web developer uses lists to create his navigation. Usually, you create the container element, create some links inside and then float the anchors in the direction he wants and calls it a day. Usually. IE though decides to make it a lot more complicated. Peruse through the following code:

    <ul>
        <li><a href="#"></a></li>
        <li><a href="#"></a></li>
        <li><a href="#"></a></li>
    </ul>
ul {
    list-style: none;
}

ul li a {
   	display: block;
   	width: 130px;
	height: 30px;
   	text-align: center;
   	color: #fff;
   	float: left;
	background: #95CFEF;
	border: solid 1px #36F;
	margin: 30px 5px;
}

A standard compliant browser renders it like so:

Tutorial Image

And the IE screen shot:

Tutorial Image

Not a particularly pleasing navigation if you ask me. Fortunately, there are 2 fixes you can try.

Fix #1

The easiest way to combat this is to float the li elements themselves instead of the anchor elements. Just add this and you should be done.

ul li {
	float: left;
}

Fix #2

The second way is to apply display: inline to the enclosing li element. In addition to fixing this bug, it also fixes the double margin bug mentioned below. Purists may not like placing block elements inside inline elements though.

ul li {
	display: inline
}

3. Double Margin on Floated Elements

This bug is probably among the first ones a web developer starting out will run into and is specific to Internet Explorer 6 and below. Triggering it is as simple as floating an element and then applying a margin in the direction it has been floated. And voila! The margin will be doubled in the rendered output. Not really something you’d look forward to while creating a pixel perfect layout.

Consider this code:

#element{
	background: #95CFEF;
	width: 300px;
	height: 100px;
	float: left;
	margin: 30px 0 0 30px;
	border: solid 1px #36F;
}

On standards compliant browsers, this is how it looks:

Tutorial Image

But here is how IE 6 decides to render it:

Tutorial Image

The Fix

The fix for this specific bug is to apply display: inline to the floated element and everything works as it is supposed to. Our previous code now changes to:

#element{
	background: #95CFEF;
	width: 300px;
	height: 100px;
	float: left;
	margin: 30px 0 0 30px;
	border: solid 1px #36F;
   	display: inline;
}

4. Inability to Have Elements with Small Heights

As part of creating a layout, you may need to create elements with very small heights as custom borders for elements. Usually, you’ll just have to add height: XXpx to the style’s declarations and you should be done. Or so you thought. Check the page in IE and you’ll probably do a double take.

As an example, look at the following code:

#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 2px;	
	margin: 30px 0;
}

And the output is just as expected: A 2 px element with a 1 px border.

Tutorial Image

And in IE:

Tutorial Image

Fix #1

The cause of this bug is pretty simple: IE simply refuses to size an element smaller than the set font size. Simply setting the font size to 0 lets you have an element as small and short as you like.

#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 2px;	
	margin: 30px 0;
    	font-size: 0;
}

Fix #2

The next best way to deal with this bug is to apply overflow: hidden to the element so it collapses to the intended height.

#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 2px;	
	margin: 30px 0;
    	overflow: hidden
}

5. Auto Overflow and Relatively Positioned Items

This bug rears its ugly head when in a layout you set the parent container’s overflow property to auto and place a relatively positioned item inside it. The relatively positioned item violates its parent element’s boundaries and overflows outside. Let me demonstrate. Look the following code:

<div id="element"><div id="anotherelement"></div></div>
#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 150px;	
	margin: 30px 0;
	overflow: auto;
}

#anotherelement{
	background: #555;
	width: 150px;
	height: 175px;	
	position: relative;
	margin: 30px;
}

And the expected output:

Tutorial Image

And IE’s output:

Tutorial Image

The Fix

The easiest way to fix this annoying bug is to just position the parent element relatively too.

#element{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 300px;
	height: 150px;	
	margin: 30px 0;
	overflow: auto;
    	position: relative;
}

6. Fixing the Broken Box Model

Internet Explorer’s misinterpretation of the box model is perhaps its unforgivable mistake. IE 6 in semi-standards compliant mode sidesteps this but this issue can still be triggered by quirks mode.

Two div elements. One with the fix applied and one without. The difference in the width and height is the sum of the paddings applied on each side.

Tutorial Image

The Fix

I am sure the quandary with the box model needs neither explanation nor demonstration so I’ll just give you the fix.

The trick is to set the width normally for all standards compliant browsers, target IE5/6 alone and then feed it the corrected width. This is how you’d usually go on about:

#element{
	width: 400px;
    	height: 150px;	
	padding: 50px;
}

This now changes to:

#element {
    width: 400px;
    height: 150px;	
   \height: 250px; 
   \width: 500px
}

Essentially, you add the padding to the original width and feed it to IE 6. The fix targets IE 6 in quirks mode alone so you need not worry about IE 6 in normal mode messing things up.


7. Setting a Minimum Width and Height

Setting an minimum height to an element is absolutely imperative when trying to convert a beautiful design into a pixel perfect design. Unfortunately, IE completely ignores the min-height property instead taking the height declared as the minimum height.

Fix #1

The fix is a hack created by Dustin Diaz. It utilizes the !important declaration to make it work. The snippet looks like so:

#element {
  min-height:150px;
  height:auto !important;
  height:150px;
}

Fix #2

The second way is to take advantage of the fact that IE can’t parse child selectors.

#element {
    min-height: 150px; 
    height: 150px;
}
   
html>body #element { 
	height: auto;
}

8. Floated Layout Misbehaving

One of the important concepts of building table-less layouts using CSS is floating elements. In most cases, IE6 handles this with aplomb but in certain cases it fumbles. When faced with unbreakable content or elements whose width exceeds its parent’s width, it causes havoc with the layouts. Let me show you.

Consider this piece of code:

<div id="container">
	<div id="element">http://net.tutsplus.com/</div>
	<div id="anotherelement"></div>
</div>
#element, #anotherelement{
	background: #95CFEF;
	border: solid 1px #36F;
	width: 100px;
	height: 150px;	
	margin: 30px;
	padding: 10px;
	float: left;
}

#container{
	background: #C2DFEF;
	border: solid 1px #36F;
	width: 365px;	
	margin: 30px;
	padding: 5px;
	overflow: auto;
}

The expected output as viewed on a standards compliant browser:

Tutorial Image

In IE:

Tutorial Image

As you can see, the first div expands itself to fit the content which ultimately breaks the layout.

The Fix

There is no elegant fix for this bug. The only way to save the layout is to apply overflow: hidden to the element but at the cost of clipping the unbreakable content. The layout will be saved but the extra content won’t.

#element{
	background: #C2DFEF;
	border: solid 1px #36F;
	width: 365px;	
	margin: 30px;
	padding: 5px;
	overflow: hidden;
}

9. Space Between List Items

IE 6 adds vertical spacing even none is specified in specific cases. Let’s look at the code first.

<ul>
 <li><a href="#">Link 1</a></li>
 <li><a href="#">Link 2</a></li>
 <li><a href="#">Link 3</a></li>
</ul>
ul {
	margin:0; 
	padding:0; 
	list-style:none;
}

li a {
	background: #95CFEF;
	display: block;
}

What it should look like:

Tutorial Image

What IE gives us:

Tutorial Image

Fortunately, there are a plethora of fixes you could try.

Fix #1

The easiest way out is to just define a width for the anchor tags and voila! everything renders as it should. Declaring a width triggers the element’s IE specific hasLayout property. You could instead define a height if you want to.

li a {
	background: #95CFEF;
	display: block;
    	width: 200px;
}

Fix #2

The next method is to just float the anchor left and then clearing it.

li a {
	background: #95CFEF;
	float: left;
    	clear: left;
}

Fix #3

The third method is to add display: inline to the enclosing li element. This also fixes the double margin bug as noted above.

li {
	display: inline;
}

Conclusion

And there you have it: the nine most common IE rendering bugs, and how to squash them. Hopefully this has saved you some blood, sweat and tears while debugging your next creation. I’ll be watching the comments section frequently; so chime in here if you are having difficulties implementing the fixes noted here.

Questions? Nice things to say? Criticisms? Hit the comments section and leave me a comment. Happy coding!


Siddharth is Siddharth on Codecanyon
Tags: CSS
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://tehkemo.com tehkemo

    Thanks, great article, bookmarked!

  • http://www.crearedesign.co.uk Stephen Webb

    This is a very useful article and one I will be bookmarking for future usage. We all know the hassle of Internet Explorers bugs, and how much time it takes to fix them, so having a good reference like this on hand can save a lot of time.

    As for the ongoing usage of IE6 and it’s endless bugs, I’d have to say that it’s simply a case of technology being superseded and whilst support for it should continue for possibly a few more years, there really needs to be a point when this is stopped, simply because as long as support is continued people will continue to use the software.

    IE 6 is now 8 years old, in technology terms this is ancient and from a previous era of the net. Simply put it was not built for the net of 2009, and along with the various security scares which regularly pop up, this is a good enough reason to begin fasing out support.

  • http://www.indev.nl Matthijn Dijkstra

    Geez, only read the first and imho its useless… you know why? You talk about ‘quirks-mode’ and that just should never happen, it only happens when there is no good doctype… so what would be the error in that case?

    You guessed it, the ‘no-doctype’ is the error. So to fix it, you should add the correct doctype, and then margin: 0 auto; works just like expected.

    IE behaves much better if a valid doctype is present.

    • http://www.ssiddharth.com Siddharth
      Author

      There are plenty of ways to trigger IE 6 into going into quirks mode even when a doctype is specified.

  • http://www.smashingshare.com/ Waheed Akhtar

    Thanks for this post. Most of the hacks are simple and very well known to everyone.

  • Gabor Lippert

    Hey that bug below the IE logo is really a disgusting one!
    Thanks for the article, it’s just that I needed for my actual work.

  • http://www.wplancer.com Banago

    Cooool collection – thanks very much!

  • Stephen

    This site is great, and there is a great mix of hardcore developers, and those who are aspiring to make their first website from scratch.

    Given that, in any online community there are also some huge egos that run around (mainly because it is easy to be 10 feet tall on the Internet)

    My advise to any beginning developer is simple…write CLEAN code. Understand what a doctype does, the difference between block and inline elements, and for gods sake use something other than !

    If your code validates – chances are you will not encounter many of these issues. I can’t tell you how many times something as silly as an unmatched tag went unnoticed – only to be caught by the validator.

    Now…regarding IE6 support…

    It’s hard for us to understand, but end users are not developers. End users are however who pays my bills, so regardless of your opinion on legacy browser support – I would highly advise expressing it with a client. 15%(ish) of the world still uses IE6. An almost equal amount still use IE7. It is not time yet to slap them with warning messages as if they were using netscape 2.0.

    To the person who said…
    “Exchange, Windows7 and Office all suck right?”

    My answer would be yes. The fact that open source solutions offer not only a more stable environment, better features and are FREE is a bit mindblowing. Given the popularity of open source, I would expect microsoft to pick up the pace.

    Anyway – happy coding!
    -Steve

  • aryan

    I highly recommend using separate stylesheet for IE 6. Link it using IF IE6 condition(you can Google for it). I don’t think using these trick in the same stylesheet would be easy to manage.

    For example- To fix double margin issue on floated element, I put floated side margin to 1/2.

    You’ll have more flexibility and only IE will read those style rules.

  • http://www.whitezine.com RaDe

    Great article :) Thanks

  • http://designintheraw.com Roy Ho

    Nice refresher!!

  • http://www.desiimg.com desi

    Thanks :)
    very useful ;)

  • http://www.meyvetabagi.com meyvetabagi

    Nice collection. Thanx :)

  • http://bwebi.com barat

    Well … IE6 is fr users who doesn’t know how to use PC and have old Windows XP or older.
    One benefit is that … IE6 users almost always have JavaScript ON.
    Thanx to this fact .. we can just use ie7.js fix (or ie8.js) and doesn’t even care IE6 users :) I do this … and I’m happier :)

    • http://peterbriers.be peter briers

      Yeah, that javascript made my life sooo much easier. No more stupid hacks.

  • http://nvmind.com Ignacio

    Good tutorial layout, straightforward

  • dj

    A complete rehash of tired old info, most of which already appeared in these pages. Surprised net tuts paid for this, yet again.

    Additionally, you rarely differentiated which IE you were talking about generating much confusion and foolish comments. IE6 is NOT the same as IE7 and/or IE8. Currently, I have as much difficulty remembering and navigating through Mozilla quirks as I do IE8 – neither of which are complete.

    IE6 is phasing out – while many of us can pontificate in our ivory towers, there, none-the-less are many people (through no REAL intend of their own) are not able to switch. I think most of us should be able to get off our high-horses long enough to have some sensitivity to the souls who are stuck with IE6 and not completely destroy their internet capabilities.

    • aryan

      I agree.

    • http://www.ssiddharth.com Siddharth
      Author

      I can’t make you change your opinion but I thought a quick list of IE bugs and fixes would be a useful addition to Net Tuts and from what other people have said, I think I am right.

      Thanks for reading. :)

  • Alon

    main point: DONT USE IE6.
    instead of fixing bugs in this browser, just ignore him and let him rest in peace.

    IE6 R.I.P

  • http://www.vatic.co.uk Matt Litherland

    LoL couldn’t of seen this article at a better time. I’m about to debug this IE Monstrosity!

    http://www.vatic.co.uk See it in Chrome perfect, See it in IE7 LoLs

  • Jayaprakash

    You’ve missed vertical alignment bottom position bug of IE (<=IE7)

  • http://www.sjlwebdesign.co.uk Sam Logan

    Bookmarked and recommended, one of the most useful web design article I have ever read. I have used the majority of these fixes in the past but other have saved hours of testing. Thank you Net Tuts, keep up the good work.

  • Kiran

    great Thanks alot.. Im new to web design i want to become master can u suggest me hoe to practice…

  • http://www.andrislinz.ch Andris

    Even though I knew all of the hacks I didn’t think of them in my last project. IE 6 is so outdated to me, but there’s still a lot of people using it. So I guess I have to check the site once again.

  • http://www.aravindtemplates.com aravind

    Really….!!! Nice…….Thanks…..

  • sam

    thanks very useful and I hate ie

  • http://www.kensfi.com Ken

    for centering the layout in IE I’m using:

    #element {background: #95CFEF; text-align:center; width:300px; height:100px; position:absolute; top:50%; left:50%; margin:-80px auto auto -125px; padding:50px}

    For the margin and padding you will have to calculate the values by yourself. I’m too lazy for doing math today :P

    text-align: left; it doesn’t make any difference, for me at least.

  • http://underpk.com underpk

    great post! always have a lot problem with IE6 :S

  • Aravind

    This is very useful…..Thank you so much

  • http://www.websitecruiser.com Phil Gapp (Kneeskrap3r)

    Thanks! This is a good (if fairly basic) explanation of some quick fixes. I like the overflow: hidden for the small height portion of the tut… works a charm :)

  • Edison Leon

    That’s one scary bug

  • http://www.petertanjung.com p-ter

    It’s a ggooodd article….

    so thankfull

  • http://www.chovy.com chovy

    I would love to see a Javascript version of the 9 most common IE javascript bugs :)

  • http://snamb.com.br Snamb

    Thanks, this helped me a lot ;D

  • http://www.34One.com Jay

    Fellow designers – Please go here and start using these code snippets so we can get out of this IE6 mess! As much as I want to stop supporting IE6, you can’t. But you can start doing things such as this to help everyone along and we as a community can help rid the world of IE6!

    http://www.ie6nomore.com/code-samples.html

  • eeeplus

    gr8…. thx

  • http://www.vetgaar.nl/ phil

    For this post sir, i will have your babies!

    • http://www.ssiddharth.com Siddharth
      Author

      :O

  • http://www.e-l-l-i-s.com Matthew

    Super helpful! Thanks very much.

  • http://www.biberltd.com/ Can Berkol

    wooo this article turned into an IRC channel :)

    Thanks for the valuable share!

  • http://www.desarrolloopensource.com seeal

    ho really good thx 4 sharing :D

  • http://variable3.com Harsha M V

    Amazing round up .

  • http://www.codeclarified.com Jason

    Good read, although I do agree with some that trying to keep a page in standards mode will help with many of these, quirks is sometimes unavoidable.

    Now I don’t know why I’m going to spend my time going into this, because(and this goes for both sides I believe) those who say “forget IE6 already” probably wont read this, or see any value in it, but…

    The continued use of IE6 has more to do with corporate applications written specifically for it, these applications will not run in a different browser, and will not run even on IE7+. Who’s fault is that? Nobody’s…. when those apps were written, IE6 is what the world had, and it very well have been their mistake for trying to be like all of the “KILL IE” folks, they jumped onto a new technology(IE6 at the time) so fast that they didn’t thoroughly think through the consequences and probably put little thought towards forward compatibility.

    Now to all who say “it’s free to upgrade to IE8 / Firefox / Chrome / etc.” – it’s not the cost of the upgrade. Trust me, if you’re reading this site, you know that the most popular web browsers are all free, this is known, next you’ll tell me the sky is blue… thanks. Writing applications, especially in a large corporate environment is not free. Until these apps are updated and brought to speed, IE6 will continue to have a viable market share. Is it Microsoft’s fault? No. Is it the web developer who continues to support IE6′s fault? No.

    For those saying “YouTube doesn’t support IE6 any more!”… well that’s all well and good… you shouldn’t be watching YouTube while you’re at the office, do that at home where you should’ve updated your browser, but any time you are working on a site where there is a good chance your visitors may be visiting from an office environment, you damn well better make sure your site is accessible in IE6. Personally I don’t think it has to be pretty in IE6, I’d rather not support it at all, and it won’t be getting any nice CSS3 effects… but then again, if a user comes across my site using Lynx, they’re not getting a pretty view either.

    I’m cutting out there, because honestly, I’ve lost track of myself in this rant

  • http://URL(Optional) sakthivel

    ya it is great! tank u for giving amazing tips

  • Geronimo McDugan

    Very Good post, IE Must die..!

  • http://maxvx.com/ maxvx

    thanks for the article, ie will die!

  • http://www.friskweb.pl Lukasz Bachur

    Very, very useful, thank you, especially for the min-height solution and double-margin problem!

    Best regards.

  • http://sand-soft.com srinufx

    Very Nice Article..
    Thanks Siddartha..

  • Jorge Sousa

    Hi, about point 2 – Staircase Effects.
    My IE 8 renders the code nice, without need of fix it with strange code!
    Don’t you render in IE 8?
    Regards

  • Jorge Sousa

    Hi, the point 4 renders well too in IE8!…
    By

  • Jorge Sousa

    Hi, the pint 5 renders well too, this article is a joke!…
    By

  • http://blog.nikc.org/ Nikke

    Jorge: this article is about IE version 6, later versions play a lot nicer than that specific thorn in a web developers hide. Pay a bit more attention when reading, and you’d have picked that up by yourself.

  • http://thetutorialist.com Brian

    The perfect tut for any web developer! I have added this post to thetutorialist.com – hope it helps!

  • bahadır

    thanks for post.. very very useful..