Differentiating CSS for IE7 IE6 and firefox

Submitted by Nima Mehrabany on Sat, 10/13/2007 - 23:12


if you put # before any css tag, only IE 7 and IE 6 will read that line.
if you put _ before any css tag, only IE 6 will read that line.



width: 560px;     /* All other browsers */ 
#width: 558px;    /* IE 6 & 7 */ 
_width: 557px;    /* IE 6 */


just remember to keep this order.

isport365 adalah situs judi casino online yang terbaik yang menyediakan beragam permainan Casino online seperti Evolution gaming, Playtech, PRagamtic Casino, Asia Gaming dan lain2

Tom Bigbee (not verified)

Tue, 03/04/2008 - 21:06

Hi Nima,
I am 25 year veteran DOS and Windows programmer and am just now learning XHTML/CSS to create a web site.

This method seems to work in these 3 major browsers and assume it will not kill any others.

When I submit it to the W3 CSS Validator it complains. A sample:
html {
font-size: 12px; /* Firefox+ */
#font-size: 75%; /* IE6, IE7 */
_font-size: 100%; /* IE6 only */
font-weight: normal;

W3C CSS Validator Results for file://localhost/TextArea
Sorry! We found the following errors
URI : file://localhost/TextArea
3 html Parse Error - .font-size: 75%;
6 Parse Error - : 100%; font-weight: normal; }

I also found a similar suggestion using a period instead of pound sign but it also fails.

Using the !important validates but doesn't give as much control.

Is this something we will have to live with?


Hi Tom.<br />
Actually this trick, !important, period and ... are not valid structures for CSS.<br />
Since I rarely need to use this trick in my style sheets, I ignore any validation error about that. <br />
<br />
Regards.<br />

Örgü Modeli (not verified)

Sun, 06/29/2008 - 19:34

css Font examples , Properties , Attribute - - //

Anonymous (not verified)

Mon, 03/31/2014 - 20:07

Nima, thank you for posting this amazing tip. Like you mentioned, CSS (Cascading Style Sheets) are very powerful and do have many advantages over plain HTML coding. The trouble is finding all of these powerful gems of information that make a website work in all browsers like we want them too. The big sites that go over the CSS syntax and commands are very good but tend to fail when it comes to the information that you provided in this post. I thank you kindly for sharing this tip as well as the proper layout or syntax.

Simple Instagram Feed