Simon Willison’s Weblog

Subscribe

Safari conditional comments

11th January 2003

The current extended discussion over whether or not Safari should have some kind of specific CSS blocking technique built in (sparked off by Mark Pilgrim) reminds me of a relatively unpublicised feature of Internet Explorer called conditional comments. These specially crafted HTML comments allow web authors to specifically hide code from versions of IE, or alternatively to hide code from any browsers that are not a specified version of IE. Here’s how they work:

<![if !IE 5]>
<p>This HTML only visible to non-Microsoft browsers or
IE versions older than IE 5</p>
<![endif]>

<!--[if IE 5.0]>
<p>This HTML only visible to IE version 5</p>
<![endif]-->

The downside of this approach is that it encourages ugly browser specific code to be added to the HTML of a page. Adrian Holovaty’s suggestion for Safari is similar but, in my opinion, more elegant as the unpleasant code is restricted to the stylesheet (I always prefer nasty hacks to stay out of the way in the stylesheet rather than rearing their ugly heads in my markup)

Previously hosted at http://simon.incutio.com/archive/2003/01/11/safariConditionalComments