Skip to main content

Blog Post

Pro Tip: How to Write Conditional CSS for IE10 and 11

While working on recent Drupal projects, I learned that Internet 10 and 11 (IE10-11) no longer support IE conditional comments. Conditional comments allow us to target specific versions or version ranges of IE to correct bugs or inconsitentices that normally are not present on other browsers. Typically for IE9 and below, we have been able to write conditional css by using something like this:

<!DOCTYPE html>
<!--[if IE 8 ]> <html class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="no-js ie9"> <![endif]-->

The code above allows us to add a css class to the html tag which only becomes available if the browser we are using is one of the ones above (IE 8 or 9). This is extremely helpful because with this class we can now write css styles that only apply to those versions of IE.

Writing conditional code based on the IE version is never desired but it comes as a necessity to address bugs or correct style inconsistencies between IE and the rest of the browsers.

How to Conditionally Target IE10 and 11

There is no question that IE10 and 11 are an improvement from previous versions of IE, but unfortunately there are times when they too need special attention. In order to conditionally target IE10 and 11 we can now use a special media query:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    // IE10+ CSS here

With the above media query in place you are now ready to conditionally target IE10 and 11. For IE 9 and below, we can continue to use the usual conditional comments.

Additional Resources
Ultimate Mark Up Control in Views | Blog 
Responsive Images in D8 | Blog
Why Good Mark Up Matters | Blog

Mario Hernandez

Meet team member, Mario Hernandez

Mario is the Head of Learning at Mediacurrent with over 10 years of public speaking and training experience. He is a regular speaker and trainer at tech conferences including Drupal...

Learn more about Mario >
Access icon Up arrow icon Drupal 8 icon Facebook icon - white Facebook icon - blue outline Facebook icon - yellow Hollow right arrow icon Hollow right arrow icon - white LinkedIn icon - white LinkedIn icon - hollow LinkedIn icon - blue outline LinkedIn icon - yellow Mediacurrent wordmark Quote icon Twitter icon - white Twitter icon - hollow Twitter icon - blue outline Twitter icon - yellow Youtube icon - white Youtube icon - yellow