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

The event listener $(window).on('popstate') does not function properly in Internet Explorer

$window 'popstate' event is not functioning properly in IE when using the browser back button. Here is the code snippet used to remove certain modal classes when navigating back. $(window).on('popstate', function(event) { event.pre ...

What is the best method for extracting the innerHTML value of html tags using a css selector or xpath?

I am currently struggling with retrieving the HTML inner text value using CSS selector or XPath. While I can achieve this using document.getElementById, I am unable to do so using selectors. I can only print the tag element but not the text from it. For e ...

When the next button is clicked, the button content disappears

I am struggling with a problem involving two buttons that store tables. The issue is, I want the table to disappear when the second button is clicked and show the contents of the second button immediately after clicking it once, rather than having to click ...

A versatile CSS solution for fixed background images that stretch to fit any screen height across multiple browsers

Similar Question: Stretch and Scale CSS Background I am interested in finding a method to create a background with specific criteria: - remain fixed in place - adjust proportionally based on the window's height - work across all browser types or ...

I rely on the angular-responsive-carousel library for my project, but unfortunately, I am unable to customize the arrow and dots

When it comes to CSS, I utilize ng deep style in Angular 10 to make changes for browser CSS. However, I am facing an issue where the problem is not being resolved by my CSS code. Here is a snippet of my code: > ::ngdeep .carousel-arrow { > b ...

A distinctive web page featuring an engaging image backdrop: captivating content effortlessly scrolling beneath

On my website, I have implemented a background image with a fixed transparent header. When scrolling down, I want the main content to be hidden beneath the header. To achieve this effect, I used the -webkit-mask-image property. However, this approach affec ...

The animation feature in Angular JS seems to be malfunctioning

Currently in the process of creating a slideshow using AngularJS, similar to the one found at this link, which includes navigation arrows (next and prev). Here is the HTML code snippet: <div class="carousel"> <div class="left"><input ty ...

Adaptive Container with Images that are not stretched to full width

Is there a way to achieve the same effect as seen in images 2 and 3 here: Although these images already have their own "padding," I'm curious if it can be replicated using just jQuery and CSS? I would appreciate any help or insights on this. Thank y ...

Incorporate a CSS framework into the Angular vendor bundle

My current situation : The website is built with Angular 4 Started using Angular Starter Kit Utilizing Semantic UI as the CSS framework The challenge I'm facing : Integration of Semantic UI into webpack is not having any impact. Steps I've ...

The positioning of the parent element shifts as a result of the CSS

What causes a vertical position change in buttons with content floated left or right? Take this example http://jsfiddle.net/8ff6dhou/ <button>aaa</button> <button><div style="float:left">bbb</div></button> <button> ...

Update the jQuery Mobile components on the page by refreshing them after dynamically adding them using AJAX and PHP

I have developed a PHP script that dynamically renders three form elements for each entry in a database. The script generates HTML output similar to the following example: <!-- Entry 1 --> <div data-role="fieldcontain"> < ...

The height of the Material UI Paper component is not appropriately matched with the parent component

I am currently working with the Paper component that contains a Card component, and I am trying to make its height fill the entire screen. To simplify the problem, I have provided the following code: import React from "react"; import { makeStyles ...

Form-linked Progress Bar

This is a little project I created (for fun and learning purposes, even though it may not be the most optimized solution). If you're interested, here's the link to the code: https://codepen.io/paschos/pen/xxGXMQb I'm currently seeking assi ...

The issue of MUI components overlapping arises during window resizing

I am currently working on a chat component that includes both the chat display and message input fields. function Chat() { const chatBoxStyles = { bgcolor: "red", height: "70vh", mt: "1rem" }; const messageIn ...

Struggling with the Nivo slider not loading properly?

Check out my personal website. I'm having an issue with my Nivo slider not displaying properly - it just keeps loading. Any ideas on why this is happening and how I can fix it? Below is the CSS I am using: #slider { position:relative; width: ...

Using various colors to highlight specific sections of a letter or number

I am striving to recreate the unique image shown below, particularly interested in achieving the multi-colored effect on the numbers. This aspect of having different colors for parts of the number is intriguing and I would love to learn how it's done. ...

Design inspired by dot matrix patterns

Is it possible to create a background HTML page filled with a dot matrix designing tool? Can anyone provide guidance on how to achieve this? If I need to use a background-image for this, where can I find the appropriate picture? Thank you to everyone in ...

Clicking elements reveal but page height remains unchanged?

Clicking on a label within #row-product_id_page-0-0 triggers the display of #row- elements as shown in the code snippet below: $('#row-product_id_page-0-0 label').click(function() { var str = $(this).find('.am-product-title').text ...

When the jquery.show() function is invoked, scrollbars are displayed on the screen

I am encountering an issue with a flydown menu that includes a scrollable div. The div is about 400 pixels in height, causing scrollbars to appear in the drop down menu. When I hover over it, I trigger the show method as follows: $("#flydown").show(); Al ...

Utilize text wrapping to ensure a fixed maximum height for content display

I am in need of a div that contains text spanning multiple lines, with both a fixed width and a maximum height. Currently, I have applied the CSS property overflow: hidden;. However, my issue arises when the last line of text exceeds the maximum height of ...