Using Conditional Comments in Your HTML

Internet Explorer is a fickle browser that often doesn’t cooperate with CSS rules like most other browsers do, which can really make the styling of certain elements a problem. To remedy this, you may sometimes choose to include a separate stylesheet that will load ONLY when the browser is Internet Explorer. An easy way to do this is to include conditional comments in the <head> section of your HTML files, like this:

  1. <!-- [if iE] >
  2. <link rel="stylesheet" type="text/css" href="path/to/IE/stylesheet.css" />
  3. <! endif -->

You can also use the above code to target certain versions of Internet Explorer. You just need to change the first line to specifically select the exact version of IE you want to target. For example:

Join us in our newest publication: