Identifying Internet Explorer version through CSS functionality and feature detection

As of IE10, browser detection tags are no longer supported for identifying a browser.

In order to detect IE10, I am utilizing JavaScript and a technique that tests for certain ms prefixed styles like msTouchAction and msWrapFlow.

I would like to do the same for IE11, but I am assuming that all the styles supported in IE10 will also be supported in IE11. Can someone assist me in identifying unique IE11 styles or capabilities that can differentiate the two?

Additional Information

  • I prefer not to rely on User Agent type detection due to its unreliability and susceptibility to change. Additionally, I have heard that IE11 intentionally conceals its identity as Internet Explorer.
  • An example of how the IE10 capability testing functions can be found in this JsFiddle (not created by me), which served as the basis for my testing.
  • I anticipate receiving responses criticizing this approach. However, my goal is to differentiate between IE10 and IE11+ to progress with a capability-based detection method in the future, especially when dealing with poorly implemented features claimed to be supported in IE10.
  • This test is complemented by a Modernizr test that adjusts functionality to less sophisticated behavior as a fallback. This is not related to crucial functionalities.

Although I am currently using Modernizr, it does not address this issue.

Answer №1

In light of the changing landscape, I have made updates to the following:

IE 6

* html .ie6 {property:value;}

or

.ie6 { _property:value;}

IE 7

*+html .ie7 {property:value;}

or

*:first-child+html .ie7 {property:value;}

IE 6 and 7

@media screen\9 {
    .ie67 {property:value;}
}

or

.ie67 { *property:value;}

or

.ie67 { #property:value;}

IE 6, 7, and 8

@media \0screen\,screen\9 {
    .ie678 {property:value;}
}

IE 8

html>/**/body .ie8 {property:value;}

or

@media \0screen {
    .ie8 {property:value;}
}

IE 8 Standards Mode Only

.ie8 { property /*\**/: value\9 }

IE 8, 9, and 10

@media screen\0 {
    .ie8910 {property:value;}
}

IE 9 only

@media screen and (min-width:0\0) and (min-resolution: .001dpcm) { 
 // IE9 CSS
 .ie9{property:value;}
}

IE 9 and above

@media screen and (min-width:0\0) and (min-resolution: +72dpi) {
  // IE9+ CSS
  .ie9up{property:value;}
}

IE 9 and 10

@media screen and (min-width:0) {
    .ie910{property:value;}
}

IE 10 only

_:-ms-lang(x), .ie10 { property:value\9; }

IE 10 and above

_:-ms-lang(x), .ie10up { property:value; }

or

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
   .ie10up{property:value;}
}

The utilization of -ms-high-contrast ensures that MS Edge is not targeted, as Edge does not support -ms-high-contrast.

IE 11

_:-ms-fullscreen, :root .ie11up { property:value; }

Javascript alternatives

Modernizr

Modernizr runs quickly on page load to detect features; it then creates a JavaScript object with the results, and adds classes to the html element

User agent selection

Javascript:

var b = document.documentElement;
        b.setAttribute('data-useragent',  navigator.userAgent);
        b.setAttribute('data-platform', navigator.platform );
        b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');

Adds (e.g) the below to html element:

data-useragent='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'
data-platform='Win32'

Allowing very targetted CSS selectors, e.g.:

html[data-useragent*='Chrome/13.0'] .nav{
    background:url(img/radial_grad.png) center bottom no-repeat;
}

Footnote

If possible, identify and fix any issue(s) without hacks. Support progressive enhancement and graceful degradation. However, this is an 'ideal world' scenario not always obtainable, as such- the above should help provide some good options.


Attribution / Essential Reading

  • Jeff Clayton | Browserhacks.com
  • Keith Clarke
  • Paul Irish
  • Web Devout
  • The Spanner

Answer №2

If you want to specifically target IE10 and IE11 (excluding Edge), follow these steps:

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {  
   /* Place your specific CSS styles for IE10 and IE11 here */   
}

Answer №3

After much exploration, I devised my own unique solution to address the issue.

By scouring the Microsoft documentation, I stumbled upon a new IE11 exclusive style called msTextCombineHorizontal.

In my experiment, I first evaluate for IE10 styles and if they match positively, then proceed to check for the IE11 exclusive style. If located, it signifies IE11 or later; otherwise, it's labeled as IE10.

Snippet: Detect IE10 and IE11 via CSS Capability Testing (JSFiddle)

 /**
  Detect IE 10 using JavaScript and CSS property detection.
  
  # 2013 by Tim Pietrusky
  # timpietrusky.com
 **/ 

 // Specific IE 10 CSS properties
 var ie10Styles = [
     'msTouchAction',
     'msWrapFlow',
     'msWrapMargin',
     'msWrapThrough',
     'msOverflowStyle',
     'msScrollChaining',
     'msScrollLimit',
     'msScrollLimitXMin',
     'msScrollLimitYMin',
     'msScrollLimitXMax',
     'msScrollLimitYMax',
     'msScrollRails',
     'msScrollSnapPointsX',
     'msScrollSnapPointsY',
     'msScrollSnapType',
     'msScrollSnapX',
     'msScrollSnapY',
     'msScrollTranslation',
     'msFlexbox',
     'msFlex',
     'msFlexOrder'
 ];

 var ie11Styles = [
     'msTextCombineHorizontal'
 ];

 /*
  * Test all IE-specific CSS properties
  */
 var d = document;
 var b = d.body;
 var s = b.style;
 var ieVersion = null;
 var property;

 // Check IE10 properties
 for (var i = 0; i < ie10Styles.length; i++) {
    property = ie10Styles[i];

    if (s[property] != undefined) {
        ieVersion = "ie10";
        createEl("IE10 style detected: " + property);
    }
 }

 // Check IE11 properties
 for (var i = 0; i < ie11Styles.length; i++) {
     property = ie11Styles[i];
 
     if (s[property] != undefined) {
         ieVersion = "ie11";
         createEl("IE11 style identified: " + property);
     }
 }

 if (ieVersion) {
     b.className = ieVersion;
     $('#versionId').html('Browser Version: ' + ieVersion);
 } else {
     createEl('Not IE10 or 11.');
 }

 /*
  * Helper function to generate a DOM element
  */
 function createEl(content) {
     el = d.createElement('div');
     el.innerHTML = content;
     b.appendChild(el);
 }
body {
    font: 1.25em sans-serif;
}
div {
    background: red;
    color:#fff;
    padding: 1em;
}
.ie10 div {
    background: green;
    margin-bottom:.5em;
}
.ie11 div {
    background: purple;
    margin-bottom:.5em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h1>Detect IE10 and IE11 through CSS Capability Testing</h1>


<h2 id="versionId"></h2>

I intend to expand the code example with additional styles once uncovered.

Please note: This approach may categorize IE12 and IE13 as "IE11", assuming those styles persist. Further assessments will be included as new versions emerge, ideally allowing reliance on Modernizr again.

I employ this test for fallback mode implementation. The alternative styling is simply more subdued aesthetically without impacting functionality.

Answer №4

Here is a solution that appears to be effective:

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {  
   /* Styles specific to IE10+ can be placed here */  
}

Link to the reference for more information

Answer №5

Here is a technique for distinguishing between <=IE11 and >IE11 ("Edge") starting from the year 2017:

@supports not (old: ie) { /* include code here for browsers that are not old versions of Internet Explorer */ }

For further clarification, consider this example:

body:before { content: 'old ie'; }
/**/@supports not (old: ie) {
body:before { content: 'not old ie'; }
/**/}

This method is effective because IE11 does not support @supports, whereas all other relevant browser and version combinations do, as highlighted in this resource.

Answer №6

If you want to ensure compatibility with IE11, you can write your code as usual and then utilize the @supports feature to check for properties not supported in IE11, such as grid-area: auto.

You can then create styles specifically for modern browsers within this block. Since Internet Explorer does not support the @supports rule, it will display the original styles, while modern browsers that do support @supports will override these styles.

.my-class {
// In IE, the background color will be red
background: red;

   // In modern browsers, the background color will be blue
    @supports (grid-area: auto) {
      background: blue;
    }
}

Answer №7

Success! It did the trick

if(navigator.userAgent.match(/Trident.*rv:11\./)) {
    $('body').addClass('ie11');
}

Following that, in the stylesheet, targeted items are identified by

body.ie11 #some-other-div

Is it time for this web browser to retire?

Answer №8

Give this a shot:

/*------Unique style for Internet Explorer 11---------*/
 _:-ms-fullscreen, :root 
 .my-special-class 
{ 
  font-size: 1.3em;
  position: absolute;
  top: -2em;   
}

Answer №9

Discover more about CSS with this informative article: Exploring CSS User Agent Selectors

Essentially, by implementing the following script:

var element = document.documentElement;
element.setAttribute('data-useragent', navigator.userAgent);
element.setAttribute('data-platform', navigator.platform );
element.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');

You can now utilize CSS to target specific browsers and versions.

For Internet Explorer 11, you could apply the following styling:

Check out this FIDDLE for an example

html[data-useragent*='rv:11.0']
{
    color: green;
}

Answer №10

Utilize the attributes listed below:

  • !!window.MSInputMethodContext
  • !!document.msFullscreenEnabled

Answer №11

To apply a specific class to the body tag, it is recommended to utilize Modernizr.

Additionally:

function findIEVersion()
{
  var version = -1;
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var userAgent = navigator.userAgent;
    var regex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (regex.exec(userAgent) != null)
      version = parseFloat( RegExp.$1 );
  }
  else if (navigator.appName == 'Netscape')
  {
    var userAgent = navigator.userAgent;
    var regex = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
    if (regex.exec(userAgent) != null)
      version = parseFloat( RegExp.$1 );
  }
  return version;
}

Please be aware that IE11 is currently in preview, and there may be changes to the user agent string before final release.

The User-agent string for IE 11 at present is as follows:

Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko

Thus, for versions 11.xx, you can test with the following code snippet:

var isIE11 = !!navigator.userAgent.match(/Trident.*rv 11\./)

Answer №12

If you're looking for a reliable solution, consider using Layout Engine v0.7.0. This tool utilizes browser feature detection to identify not just IE11 and IE10, but also older versions like IE9, IE8, and IE7. Additionally, it can recognize various other popular browsers, including those used on mobile devices. By adding a class to the html tag, Layout Engine is user-friendly and has shown strong performance in extensive testing.

Answer №13

If you are utilizing Modernizr, distinguishing between IE10 and IE11 is a breeze.

One key difference is that IE10 does not support the pointer-events property, while IE11 does. (caniuse)

To cater to these variations, you can use specific CSS based on the class added by Modernizr:

.class
{ 
   /* Styling for IE11 goes here */
}

.no-pointerevents .class
{ 
   /* Styles for handling IE10 go here */
}

Answer №14

To maintain the standard of conditional comments in HTML, you can utilize JavaScript to add a specific class. Here is an example code snippet:

  var ua = navigator.userAgent,
      doc = document.documentElement;

  if ((ua.match(/MSIE 10.0/i))) {
    doc.className = doc.className + " ie10";

  } else if((ua.match(/rv:11.0/i))){
    doc.className = doc.className + " ie11";
  }

Another option is to use a library such as Bowser:

https://github.com/ded/bowser

You can also consider using Modernizr for feature detection:

Answer №15

Identifying Internet Explorer (IE) and its various versions can be done quite easily, thanks to its distinctive features:

var uA = navigator.userAgent;
var browser = null;
var ieVersion = null;

if (uA.indexOf('MSIE 6') >= 0) {
    browser = 'IE';
    ieVersion = 6;
}
if (uA.indexOf('MSIE 7') >= 0) {
    browser = 'IE';
    ieVersion = 7;
}
if (document.documentMode) { // from IE8 onwards
    browser = 'IE';
    ieVersion = document.documentMode;
}

.

This method also captures higher IE versions running in Compatibility Mode/View. Then, it's just a matter of applying conditional classes:

var htmlTag = document.documentElement;
if (browser == 'IE' && ieVersion <= 11)
    htmlTag.className += ' ie11-';

Answer №16

Here is a possible solution:

if(document.documentMode) {
  document.documentElement.className+=' ie'+document.documentMode;
}

Answer №17

Encountered a similar issue while working with a Gravity Form on a WordPress site in Internet Explorer 11. The column layout of the form, set to "display: inline-grid", caused a disruption in the design. However, by implementing the suggestions mentioned above, I was able to successfully address the layout inconsistency!

@media all and (-ms-high-contrast:none){
  *::-ms-backdrop, .gfmc-column { display: inline-block;} /* IE11 */
}

Answer №18

Instead of focusing on detecting "internet explorer," perhaps it would be more beneficial to consider what features your website needs to function properly. If a browser supports those features, then it should be deemed suitable. If not, it may be best to alert the user.

For further assistance, I recommend visiting instead of proceeding with your current approach.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript code that displays items in a shopping cart

I've set up the HTML and JS functionality for the cart, but I'm facing an issue where the JS doesn't render the cart items when the shop item is clicked. The styling in my HTML is done using Tailwind. If anyone could provide some assistance ...

Adjust the parent element's height based on the child element's height, taking into consideration their respective positions

Is there a way to adjust the height of the parent element that has a relative position based on the height of child elements with absolute position? In the example below, the height of the .parent element is displaying as 0px Note: I am looking for a so ...

Guide on adjusting the darkness of a MaterialUI Avatar component image and adding text to it

I'm currently working with the Avatar component from Material UI along with Tailwind CSS. I found that by simply adding the image URL to the src, it displays the avatar successfully. <Avatar alt="Cindy Baker" src="https://mui.com/sta ...

React Semantic UI - A modern solution for semantic web development

Having trouble styling React Components with Semantic UI for React (). I've customized Semantic UI's styles Core, but sometimes I need to incorporate my own styles into their components. I prefer using the BEM methodology for CSS naming conventi ...

Lines running horizontally on either side of the text

I recently found a helpful solution on Stack Overflow, but it's not exactly what I'm looking for due to two main reasons: I am unsure how to adjust the width of the lines to make them shorter. The solution uses H2, however, I have already d ...

What is the best way to line up changing column values with changing row values in an HTML table?

In its current state, the data appears as follows without alignment: The data columns are housed within a single variable due to the presence of multiple excel tabs with varying columns. Within the tr tag, rows are checked to match specific columns. The ...

Ways to avoid divs overlapping on a mobile device?

If you visit this page: The recent searches section displays correctly on a computer, but it overlaps with the footer when viewed on an iPhone 6. What steps can I take to avoid this issue? ...

Remove the active class after it has been clicked for the second time

Currently, I am working on a menu/submenu system where I want to toggle active classes when clicked. However, I encountered an issue - if the same menu item is clicked twice, I need to remove the active class. Initially, I tried using jQuery's toggleC ...

Conceal Tooltips with Materialize CSS

I'm trying to figure out how to hide the tooltip that appears when hovering over this element using Materialize CSS. <li><a class="btn-floating green" onclick="window.print();return false;"><i class="material-icons tooltipped" data-pos ...

Unable to activate tr:hover override feature in Dash app

Although I am new to Dash, I am well-versed in Python, HTML, and CSS. I have a simple structure that displays a DataTable. Here is the code snippet: def render_datatable(df=None, id=None): dt1= dash_table.DataTable( id=id, columns=[{&q ...

Switch up the font style of the title element

Is it possible to modify the font-family of the title attribute in an input field using either JavaScript or jQuery? <input type="text" title="Enter Your Name" id="txtName" /> ...

Adaptable Image Maintains Integrity

My code is generating the following output: While I want the images to resize when dragged in, one of the right-hand images does not move below the main image as intended. Here is my code: Can anyone help me resolve this issue? Check out my CSS and HTML ...

The dropdown menu is obscured by the toolbar

When using ionic4/angular, I want a dropdown menu to display upon clicking on the ion-avatar. However, the dropdown menu is hiding in the toolbar. I have tried setting z-index but it did not work. Any suggestions would be appreciated. You can find the sta ...

What is the best way to update a targeted component in React when triggered by an event handler?

Your goal may seem straightforward, but getting a reference to a specific component using this is proving to be tricky. Here we have our App.js file: import React, { Component } from 'react'; import CoolBox from './coolBox.js'; import ...

Struggling with implementing CSS in React even after elevating specificity levels

I am struggling with a piece of code in my component that goes like this: return ( <div className="Home" id="Home"> <Customnav color="" height="80px" padding="5vh"/> <div className= ...

The alignment of bullets in CSS property list-style-position is off

I'm encountering an issue with aligning the list items. I've been using the CSS property list-style-position: inside; Typically, the bullet points appear outside of the text, like this: https://i.stack.imgur.com/LcVB0.png This doesn't seem ...

Ensuring my form adjusts effortlessly to the sprites

I need assistance in making my contact form responsive to match the eagle sprite on this specific webpage: The goal is to ensure that as the screen size changes, the eagle's mouth aligns perfectly with the form. While the sprites and form are both re ...

How can I apply max-width and max-height to a background image?

It seems like a simple task. I am currently transitioning my layout to become more fluid by working on creating scalable images. While using the img tag and setting max-width to 100% is effective, I am considering using a div with the image set as its bac ...

What is the best way to confine the child elements within a parent element using CSS?

Check out my CSS and HTML code here: https://jsfiddle.net/z2cc11yk/ Here's the HTML: <div class="progressbar-container"> <div class="progressbar-text">125%</div> <div class="progressbar-progress" style="background-color: red; wi ...

Differences between flexible and fixed-width columns in responsive grid layouts

Recently, I've been diving into the world of flexbox and creating my own grid system. Traditionally, when building a grid system using floats, you have to calculate the number of columns per layout and assign percentages for each column's width. ...