Grow your CSS skills. Land your dream job.

Last updated on:

Detect Internet Explorer

<script type="text/javascript">

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=8)
  document.write("You're using IE8 or above")
 else if (ieversion>=7)
  document.write("You're using IE7.x")
 else if (ieversion>=6)
  document.write("You're using IE6.x")
 else if (ieversion>=5)
  document.write("You're using IE5.x")




  1. Permalink to comment#

    Sniffing user agent is not a “safe” solution.
    I prefer the Dean Edwards one:

    var isMSIE = /*@cc_on!@*/false;

    (More here: )

  2. CaTaHaC
    Permalink to comment#

    Or simply use what has already been built and not rewrite it:
    if ($ { … }

  3. Mahroof Ali

    using conditional comments is a lot easier, is’nt it?

    • Michael
      Permalink to comment#

      The problem with conditional comments is that IE 10 no longer supports them

    • ajay
      Permalink to comment#

      but conditional comments is not working in ie 10

  4. Prashant

    this code does not work for IE11, can you modify the MSIE to detect IE11 also, Please help.

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".