---
title: "Simplest Css Hack Ever"
url: https://thecancerus.com/simplest-css-hack-ever/
date: 2008-05-08
modified: 2008-05-08
author: "ican"
description: "\"What?!! the dawn of IE8 is upon us and someone is writing about css hack for IE\" Well... my response is simple, you don't need to use this it's just..."
categories:
  - "css"
tags:
  - "akhack"
  - "comment hack"
  - "css"
  - "css exploit for internet explorer"
  - "css hack"
  - "extended underscore hack"
  - "underscore hack"
word_count: 419
---

# Simplest Css Hack Ever

"What?!! the dawn of IE8 is upon us and someone is writing about css hack for IE"

Well... my response is simple, you don't need to use this it's just for your knowledge. ;)

I have been using this trick for two years now, as most of the other magical css hack were above my head.

I discovered this accidentally, and it might not be an hack also, but i use it a lot in my work.

**So what is this hack?**

Simple, just put *'//' in front of any valid css declaration*, most of the other browser will treat this as comment and ignore it, while our friend Internet Explorer will not treat this as comment and render the property.
<style>

.test{
color:red;
//color:green;
}

</style>

<p class='test'>I will be green in Internet Explorer, red in all other browsers</p>
The only thing that you must *note is the sequence of statements*. The declaration that you want to override in IE should come after the declaration for other browsers. What it means is that if you put the *//color:green* first in above example then even IE will show the color of text as red.

Example:

I will be green in Internet Explorer, red in all other browsers.

**How it works?**

The idea is very simple as second line is treated as comment by other browsers like firefox, they simply ignore it. Internet Explorer on the other hand does not treat second statement as comment, so it simply overrides the first statement. The only know limitation is that it does not provide you with any means to differentiate IE6 and IE7

This is kind of interesting, for once i think IE followed the right path while others deviated to make writing comments easier for us developers.

I had googled to check if some one has already written about it, but i was surprised to see that no one had written anything about it, while they have listed all the big and complex hacks.

I thought it must be because this is so simple... or may be nobody ever tried it? who knows?

While writing this post i was even tempted to name this hack as *'akHack', *and thought better off it.

Any ways I just want to satisfy my curiosity, did you knew about this?

update [10 may]: finally i know the name for this hack it is called Underscore hack, thanks to neil and chris. So what i am using is basically a variation of or [extended underscore hack](http://annevankesteren.nl/2005/07/ie-hack).