---
title: Targeting and filtering IE with relative ease
date: 2010-05-16 22:47
slug: targeting-and-filtering-ie-with-relative-ease-2
tags:
- html
- ie6
- webdesign
---

[james scariati]: http://jscariati.wordpress.com/2010/05/16/target-every-version-of-ie-from-a-single-stylesheet/

I just read a [blog post by James Scariati][james scariati] regarding a method to target every version of IE from a single stylesheet. The idea was to add a wrapper div with a specific class using conditional comments, allowing you to target IE6 using CSS specificity rather than separate stylesheets. The commenters took it a bit further, and I decided to test out a slight permutation.

Using the double comment trick (as shown below) to filter IE, you can add a series of statements that put a class on the body tag for the page (without resorting to javascript or browser sniffing). I've given it a quick test in Firefox, Safari and Internet Explorer 6, 7 and 8. It seems to be working quite well. This may be my new body tag! The code below includes a button that will pop up an alert showing which class has been assigned to the body tag after the page loads.

```
	<!DOCTYPE html>
	<html>
	<head><title>IE Targeting</title></head>

	<!--[if ! IE]><!--><body class="notIE"><!--<![endif]-->
	<!--[if IE 6]><body class="ie6"><![endif]-->
	<!--[if IE 7]><body class="ie7"><![endif]-->
	<!--[if gte IE 8]><body class="ie8"><![endif]-->

		<button onClick="alert(document.getElementsByTagName('body')[0].className);">Check it</button>

	</body>
	</html>
```

Thanks to James Scariati for the idea, Greg McAusland for the evolution of it!

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
