How to Target CSS Styles to Internet Explorer 6 and IE7
This article has been updated on January 30, 2009. Please see the bottom of this article for the gory details.
Today, for the umpteenth time in the past month, I found myself coding a design to work around bugs in the Internet 6 and 7 web browsers. I had found and posted a link to a great site on our Resources pages, on the HTML and CSS page, and realized that it should be posted on the blog as well.
Basically, to target a style so that only Internet Explorer 6 and 7 web browsers will respond, add an asterisk before the definition like this:
#some-style {
…
top: 45px;
*top: 55px; /*hack for IE6 and IE7 browsers*/
…
}
If you want to target a style so that only Internet Explorer 6 will respond, add an underline before the definition, like this:
#some-style {
…
top: 45px;
_top: 55px; /*hack for IE6 only*/
…
}
This tip is from Last Child, an excellent resource on CSS. This tip is really cool because it is lightweight and standards-compliant browsers like Firefox and Safari will ignore the hacks.
The real problem with CSS hacks, besides the fact the Microsoft browsers are so poorly coded in some ways, is future maintenance of your CSS code. At the least, you should put a comment next to any CSS element that is targeted solely to an IE browser. That way you can quickly find these hacks in the future and make changes on the day, one hopes, Microsoft releases a truly web standards compliant browser. One that requires no hacks. At worst, do not go for complicated hacks whenever possible. They’re more difficult to maintain going forward.
UPDATE (Jan 30, 2009): Please ignore what I describe above because it is non-optimal for solving this particular problem (how to make IE browsers conform to standards). Instead, the best approach to code around bugs in Microsoft browsers is to use conditional comments, as described in this absolutely brilliant SitePoint article, Internet Explorer Conditional Comments, and used on sites like this one if you select View > Source and study the page code. Also, if useful, here is the official Microsoft page about conditional comments.
Unlike the approach above, where you put into one CSS file all your styles for all browsers, conditional comments let you create separate stylesheets for separate browsers. Therefore, when IE6 goes away, for example, you simply remove the conditional comment that delivers your IE6-specific stylesheet. You don’t have to touch any styles in any other stylesheet, or hunt down every last style you tweaked for IE6 browsers. Plus your CSS code will be pristine with no hacks.
So I apologize I steered people wrong up to this point. Hopefully the links to conditional comments will more than make up for the error. And please let me know if you find a better way to solve this problem (if you’re a gazillionaire, perhaps you could buy Microsoft and cancel all their web browser software development).
URLs:
http://reference.sitepoint.com/css/conditionalcomments
http://msdn.microsoft.com/en-us/library/ms537512.aspx
http://www.last-child.com/ie7-hacks/
http://www.redwrangler.com/resources/html-and-css.php#iebugs
- Popular Articles
- Latest Stories
- Popular Stories
- How to Pick an Online ECommerce Shopping Cart: 6 Carts Reviewed
- How to Code HTML Email Newsletters
- How To Create An Editorial Process To Publish Web Content
- How to Protect Your Website Images
- How To Do Basic Search Engine Optimization for Web Pages
- How To Easily Edit DNS Zone Files To Configure Email Servers
- How To Evaluate and Hire Programmers, Without Being A Programmer
- Browse all articles
- Resources: CSS Frameworks, PSD to HTML, Text Editors and IDEs
- Free Google AdWords Campaigns for Non-Profits
- How to Find the Perfect Color and Create a Color Palette
- 6 Tips for Better Branding with Avatars
- LA Weighs Replacing Software with Google
- Apollo 11 40th Anniversary
- Xobni Organizes Your Outlook Email
- The Not-So-Hidden Politics of Class Online
- Tips for Sorting Through the Social Networks
- Cool Search Engines That Are Not Google But Still Useful
- How To Code HTML Email Newsletters (All New Version) - 270,771 views
- How To Easily Edit DNS Zone Files To Configure Email Servers - 29,793 views
- How To Create An Editorial Process To Publish Web Content - 22,814 views
- How to Protect Your Website Images - 21,980 views
- How to Pick an Online ECommerce Shopping Cart: 6 Carts Reviewed - 19,578 views
- B2B Buyers Have Very High Social Media Participation - 16,553 views
- The Big, Bad List of Search Engine Optimization Questions to Ask - 16,471 views
- Who’s Your Coding Buddy? - 16,450 views
- How to Deal with Internet Explorer 6 (IE 6) - 16,444 views
- About tweetCC and Why Licensing Your Twitter Tweets Matter - 16,386 views
Great Online Communities to Explore
Community MX - Web Design with Adobe twist
IxDA - Interaction Design
Boagworld - Web Design
SitePoint - Web Design, Coding
The Content Wrangler - Content, Content, Content
@TypeTweets - Twitter for Type-o-philes
Webmasterworld - Web Design
Get the Email Newsletter: Keep Up To Date
Stories, links, and more emailed to you every few weeks!

Connect With Us Online
We provide low-cost, how-to internet marketing information for individuals, businesses, and groups, as well as the people who support them. Learn more