Browsers other than IE treat the conditional statements as comments because they're enclosed inside comment tags.
<!--[if IE]>
Non-IE browsers ignore this
<![endif]-->
However, when you're targeting a browser that is NOT IE you have to use 2 comments, one before and one after the code. IE will ignore the code between them, whereas other browsers will treat it as normal code. The syntax for targeting non-IE browsers is therefore:
<!--[if !IE]-->
IE ignores this
<!--[endif]-->
Your code has some problems and I corrected them. Check with IE9 and other browsers. Now its working fine except in IE10 and higher (cuz IE10 and above no longer support conditional tags)
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<link href="style.css" type="text/css" rel="stylesheet" />
<head/>
<body>
<p><span class="p-style">XXXXXXXXXXXX</span></p>
<p><span class="p-style-IE">YYYYYYYYYYYYY</span></p>
<!--[if IE]>
<style>
.p-style {color:red;}
.p-style-IE {display: none;}
</style>
<![endif]-->
<!--[if !IE]><!-->
<style>
.p-style {display: none;}
.p-style-IE{color:green;}
</style>
<!--<![endif]-->
</body>
</html>
Update : For IE10 and IE11,
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
/* IE10+ specific styles go here */
}
we create a media query using -ms-high-contrast, in which you place your IE10+ specific CSS styles. Because -ms-high-contrast is Microsoft-specific (and only available in IE10+), it will only be parsed in Internet Explorer 10 and greater.