Subscribe to RSS

Weekly CSS Trick: The IE underscore hack

This week it is a hack that I am providing for everyone to enjoy, it allows you to easily add a quick style within your existing style sheet to target internet explorer. This can help so you don’t have to check your ie CSS file if is just a simple margin adjustment. Which as we all know internet explorer has some issues with, especially internet explorer 6. The underscore hack is pretty basic but I will go over the various uses for it and touch on what browsers it affects and which browsers ignore it.It used to be that underscores were illegal within CSS but since CSS 2.1 was released it is now accepted. Basically Internet Explorer will ignore the underscore and accept it as a regular CSS expression where as other browsers will ignore any CSS expressions that have an underscore in them. This makes a very quick and easy way to target internet explorer without any difficulty at all.

The browsers that are affected by this are IE6 and IE7, because IE5 adheres to older CSS specifications it actually ignores the underscore.

Listed below is an example of its use.


#element {height: 280px; _height: 280px;}

It is quite basic but can come in very handy for an easy alteration to target IE browsers when you only need to change some small information. This method is of course not recommended for any extended IE manipulations because you should use the [if ie] method for major changes. The reason for this is that you can separate your CSS out and take full advantage of style and structure separation.

Next week I will go over some ways to ensure that your divs are wrapping around your content and not stopping half way short. This can be a huge pain if your background color or image isn’t going to the bottom of your content. I have had this issue a few times in the past and at first it can be frustrating to discover the root cause.

Popularity: 5%

Whats Next?

  • Save to Delicious! Save the page

3 Responses to “Weekly CSS Trick: The IE underscore hack”

  1. Anne Says:

    Simple and to the point, I was actually searching for the trick to getcontent to wrap in a pinch.. the trick on the bottom paragraph.

  2. robbiemac Says:

    Very cool. Simple and useful. Thanks for sharing.

  3. Dwayne Charrington Says:

    I swear by this hack. It’s fast, simple, and easy to use. If you’re going to be doing extensive IE hacking, I would recommend using a condition if statement instead, otherwise you’ll have a tonne of redundant code that will mess up your perfect, valid css document when you run it through the W3C validator.

Leave a Reply


Recent comments

I’ve been on a vacation, normality will happen next week

On August 28, 2008, holiday travel wrote:

well this is useful… (at least for me) very thanks ————&# 8212;———R 12;—–...

Top 10 search engine optimization techniques

On August 26, 2008, ибп wrote:

А что, неплохо!

Styling the first post of your Wordpress blog

On August 21, 2008, cheap website design wrote:

good point you have in there! thanks for sharing with us

CSS Hack:Getting Safari to behave

On August 21, 2008, Glass wrote:

You can also target Safari with the following: body:first-of-type .class {} That is: just prepend css the rule with body:first-of-type. Simple.

Styling the first post of your Wordpress blog

On August 20, 2008, jeeremie wrote:

Hi, This solution didn’t work for me. Instead, I use this one »