Last updated on November 18th, 2015 at 03:44 am

Conditional comments Internet Explorer(IE) works only with Internet Explorer version 5 on wards.Their basic structure is HTML. The other browsers ignore them entirely since it starts with <!– and ends with –>. They are only recognized by internet explorer.
Lets take an example of an html code which has 2 buttons to be displayed. The requirement here is we need one button strictly dedicated for IE{internet explorer} and other button for all common browsers.Here is the HTML code.

 <!--[if gt IE 6]>
<input type="button" value="Only Can Be Seen With Internet Explorer">
<![endif]-->
<input type="button" value="Outside Condition">

If you put the above script in an html page. You should see 2 buttons in IE but if you run the script in Firefox or Chrome you should see only the 2nd button.

How to display the buttons with condition so that either one of the button displays according to the browser on which it is running?
put the below code in an html page.

 <!--[if gt IE 6]>
<input type="button" value="Only Can Be Seen With Internet Explorer">
<![endif]-->
<!--[if !IE]> -->
<input type="button" value="Outside Condition">
<!--<![endif]--> 

Run the script, You will be seeing “Only Can Be Seen With Internet Explorer” button on IE 5 plus and “Outside Condition” button will be displayed on all browsers other than IE [ie: Firefox,Chrome,Opera etc.,].We wont be seeing both the buttons anymore in the HTML page since we added condition for each button.
This condition is very useful when you have an HTML page where you need to run customized scripts for internet explorer.
Similarly you can use these conditions for CSS style sheet etc.,

One thought on “Conditional Comments Internet Explorer”

Leave a Reply

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