Last Updated on February 11, 2021 by Roshan Parihar
In this tutorial, learn how to define CSS for Internet Explorer and add an IE-only stylesheet. The short answer is: use the starting tag <!--[if IE]>
and the closing tag !<[endif]-->
in the head section with externally added stylesheet using the <link>
inside the tags to define only for Internet Explorer browser.
The Internet Explorer is the only browser that creates pain for the designers when they want to design a website. Because of this, you may require a separate stylesheet to add to your website which may work only when you open a website on Internet Explorer.
Let’s find out with the examples given below.
How to Define CSS Only for Internet Explorer and Add IE-Only Stylesheet
You can add IE defined the only stylesheet by using the conditional comment inside the <head> tag as given below. Use the starting tag <!--[if IE]>
and the closing tag !<[endif]-->
. After that, put an IE-only stylesheet in between this starting and the closing commented if condition tags as given below:
1 2 3 |
<!--[if IE]> <link rel="stylesheet" type="text/css" href="css/ie.css"/> <![endif]--> |
The above example contains the added ‘ie.css’ stylesheet that contains the CSS defined only for Internet Explorer. Replace your IE defined stylesheet with the above-given stylesheet name. The above stylesheet works only for the Internet Explorer browser and there is no effect on the other browsers like Chrome, Mozilla, etc.
Add Stylesheet for All Browsers Except Internet Explorer
If you want to add style or define CSS which works for all the web browsers except Internet Explorer. You can use the below given conditional comments that contain the symbol ‘!IE’ within the commented starting tag. It means, if not the Internet Explorer browser then apply the CSS.
1 2 3 |
<!--[if !IE]> <link rel="stylesheet" type="text/css" href="css/ie-not.css"/> <![endif]--> |
You May Also Like to Read.
- How to insert mailto in anchor tag link using HTML
- how to change background transparency of div element using CSS
I hope you like this tutorial on how to define CSS for Internet Explorer and add an IE-only stylesheet.