Home >

How to use conditional comments

3. March 2011

Conditional comments can be used to give special instructions meant for Internet Explorer. They are supported from Explorer 5 onwards, and it is even possible to distinguish between 5.0, 5.5 and 6.0

Here is how they can be used:

<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

A simple example could be to warn your IE6 users about the dreaded IE6 browser they are using :-)

Just copy/paste following HTML in your website to see it in action!

<!--[if lte IE 6]>
<style type="text/css">
#ie6msg{border:3px solid #c33; margin:8px 0; background:#fcc; color:#000;}
#ie6msg h4{margin:8px; padding:0;}
#ie6msg p{margin:8px; padding:0;}
#ie6msg p a.getie7{font-weight:bold; color:#006;}
#ie6msg p a.ie6expl{font-weight:bold; color:#006;}
</style>
<div id="ie6msg">
<h4>Did you know that your browser is out of date?</h4>
<p>To get the best possible experience using my website I recommend that you upgrade your browser to a newer version. The current version is <a class="getie7" href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer 7</a> or <a class="getie7" href="http://www.microsoft.com/windows/Internet-explorer/beta/default.aspx">Internet Explorer 8 (Beta)</a>. The upgrade is free. If you're using a PC at work you should contact your IT-administrator. Either way, I'd personally like to encourage you to stop using IE6 and try a more secure and Web Standards-friendly browser.</p>
<p>You could also try some other popular browsers like <a class="ie6expl" href="http://mozilla.com">FireFox</a> or <a class="ie6expl" href="http://www.opera.com">Opera</a>.</p>
</div>
<![endif]-->

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading