How to Add Stylesheets for IE Only

It is very challenging to write only one CSS file to target all the browsers, especially to target IE.

We can add the IE specific style sheets using conditional comments. So we have to add one global CSS file for all browsers, and one for IE only to override or add styles specific to IE.

Conditional comments work as follows:

Basic structure is the same as an HTML comment (). Therefore all other browsers will see them as normal comments and will ignore them entirely. But, Internet Explorer has been programmed to recognize the special syntax, resolves the if and parses the content of the conditional comment.

What if we want to include separate css files for different versions of IE, you can do this by checking browser version as follows:

To target less or greater than to a specific IE version:

We can also write IE specific styles without using conditional comments as follows:

Just add the “*html” before any css class or add “*” before any style to apply only for IE. But, this is kind of a hack, So I would recommend to use conditional comments approach.

Comments

  1. By Laci

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami