Nifty IE CSS and HTML Tricks and Tips
I see a lot of people struggling with making their website compatible in IE6 and IE7. I keep a nice little library on my computer of such useful snippets of code, I thought I’d share some to help the development world out just a bit.
CSS Reset
This helpful bit off CSS code comes from Eric Meyer. It has saved me from pulling out my hair countless times. With this reset, my websites are almost always perfect in IE7 – and about 5 minutes from perfection in IE6. It requires a little bit of extra coding, because it resets the margins on everything including ‘p’, ‘li’ and ‘ul’ tags but it’s worth it, trust me. Just stick this snippet of code at the very top of your main stylesheet and you’ll be good to go:
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center,
dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; }
body { line-height: 1; }
ol, ul { list-style: none; }
blockquote, q { quotes: none; }
blockquote:before, blockquote:after,
q:before, q:after { content: ''; content: none; }
:focus { outline: 0; }
ins { text-decoration: none; }
del { text-decoration: line-through; }
table { border-collapse: collapse; border-spacing: 0; }
PNG Fix
This fix is helpful when for design purposes, you must use a transparent PNG in IE6. I always try to replace my PNGs with JPGs or GIFs in my IE6 stylesheet (more on that below), but sometimes you just can’t, and therefor need a PNG fix. This fix from TwinHelix works great BUT you can not use it on a transparent PNG with links inside of it, inside of a positioned element. As you should be floating most of your layout, except for a few items that break the box method, this shouldn’t pose a problem most of the time.
You’ll need to download the zip file and place the iepngfix.htc and blank.gif in the main directory.
Place this bit of code inside your main or IE6 stylesheet:
img, div { behavior: url(iepngfix.htc) }
If you save your blank.gif anywhere but in the same directory as the iepngfix.htc, you’ll need to open the htc file and change the path. It’s right at the top of the file and includes a lot of commented documentation, so it shouldn’t be difficult to find. Also, you many need to add more elements, or full classes to the behavior tag, depending on where your PNGs are.
IE6 Conditional (Specific) Stylesheets
I don’t like using browser hacks in my main stylesheet, but I will use an IE6 conditional stylesheet. All this does, is read your browser, and if you’re using IE6 pulls this stylesheet underneath your main one: so you can half your doubled margins, replace your PNG backgrounds with JPGs, and basically code for IE6 without affecting other browsers. Just stick this code UNDERNEATH your main stylesheet (or it will get read over)
<!--[if IE 6]> <link href="ie6.css" type="text/css" rel="stylesheet" media="screen" /> <![endif]-->
Make IE8 Look Like IE7
This is one I always forget, because admittedly, I’m still not used to IE8 being around…but it’s quite useful. Stick this is your meta tags and it will force IE8 to read like IE7, therefor saving your poor soul from yet another browser test. (We have so many to test for already, don’t we?)
<meta http-equiv=”X-UA-Compatible” content=”IE=7″ />
These are a few of my most used and favorite. Have one you like to use that’s not above? Let me know. ![]()

Eric Meyer’s reset sheet is great but I always tweak the fonts like this:
* { font-size: 14px; }
body { line-height: 1.29em; }
That way I get a 18px vertical rythm which looks much better to me.
One of the tricks I use the most is the curved corner fix: http://www.htmlremix.com/css/curved-corner-border-radius-cross-browser
I would add -khtml-border-radius there, though.
Nice collection of fixes.
Personally I include reset and any other stylesheets like that in a separate file because I think it de-clutters the main rules of my layout.
A word of warning on Eric Meyer’s reset rule, you must include your own focus style, but he mentions that in the css file anyway.
I think the important thing to remember about reset stylesheets is that they are not set in stone and it is acceptable, if not expected, that you may have several variations of the reset stylesheet for different types of websites.
Won’t the following essentially do the same thing as your first style?
* {
border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent;
}
Or, has someone discovered that IE6 doesn’t honor the wildcard on certain tags?
@Jeremy, yes that will work but there are a many good reasons not to use the wildcard. Google around for IE6 resets, there was an awesome blog post I read recently that explains why the wildcard is bad, and would do a much better job than if I tried
Maybe my google skills are lacking but I didn’t see the article you’ve mentioned.
Which article?
in the comment I replied to you said “there was an awesome blog post I read recently that explains why the wildcard is bad”. Just noticed that comment is from 2009, so I imagine it’s been forgotten by now.
Ah it’s bad because it takes longer for the browser to render when using the wildcard to reset absolutely everything, plus it ends up reseting a lot of stuff you don’t need, so it takes more coding to get the website working.
I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work. Look forward to reading more from you in the future.