The !important Use In CSS

Sometimes we must isolate out specific versions of IE that give us grief as developers. There have been many discovered avenues in isolating certain versions of IE out of our style scheme to give specific instructions to, but none are as subtle as the !important. That’s right the !important use is for IE related issues ONLY! Aside from the ridicules fact that we have a procedure to make this one browser obey our code, let’s look at how the !important procedure works and can help us.

!important is basically giving importance to a style over all other browsers except IE6 and below. IE6 and below can’t recognize it, therefore skips over our style and hunts for another of its kind. Again because we are giving our style importance, all other browser will do the opposite and only read our important style and skip over any others.

So let’s say we want all browsers except IE6 and below to give an element a width of 500 pixels, but in IE6 and below we want this same element to have a width of say 502 pixels. We would simply use the !important helper as follows:

#element {width:500px !important; width:502px;}

Simple as that folks, now everyone in browsers who are IE6 and above equivalence will see this element at a width of 500 pixels while IE6 and below will receive our 502 pixels.

That was painless right?

Devin R. Olsen

This Article's Comments.

  1. 6
    Andres Says:

    While, that is the reason I bet most people use the !important declaration for, that is not really the purpose of it. The important declaration is to override a css rule that would have normaly be read. For example, you can override an inline style through this use in all the browsers that support

  2. 5
    nitin Says:

    i had listen abt the !important, but didn’t know how to use.Thans Devin

  3. 4
    baagdi Says:

    thanx, this is really helpfull information.

  4. 3
    Devin R. Olsen Says:

    I always enjoy feedback from my readers!

  5. 2
    tarek Says:

    thank’s a lot Devin you’are doing well,yes it’s painless

  6. 1
    Nagnedra Says:

    Thanks Its very userful�

Leave a Reply