Using Feature Detection to Drop Support for Older Browsers

Posted on April 03, 2015 - 2 Minute Read

EDIT This is an old article, and the recomendations are no longer best practice.

A lot of people are familiar with conditional classes, which is a great alternative to conditional stylesheets or css hacks. However, these only target IE. Even though most of us have become dependent on modern browsers like Chrome or Firefox, we still forget that they are not immune to problems. And let's not forget mobile browsers like Opera Mini or Android Browser.

This is were feature detection and Modernizr come into play. With Modernizr, you can see if a browser supports a feature, such as css3 transforms. If it doesn't, a class of no-transform will be added to the <html>. This allows you to not just target IE, but any browser, and then then create a fallback.

So, what if you're looking to drop support, rather than create a fallback? Using jQuery, I append the affected <html> with a code snippet letting users know their browser is not supported. This is better than always having this snippet in the code because it will be the top most element, so search engines and screen readers will pick it up.

$('').prepend( "<div class='browsehappy'><p>You are using an <strong>outdated</strong> browser. Please <a href='''>upgrade your browser</a> to improve your experience.</p></div> " );

Then you can use css or scss to style it.

.browsehappy {
  background: red;
  color: white;
  padding: 20px;
  text-align: center;

  a {
    &:visited {
      color: white;

    &:active {
      color: black;

Below is the final result. This is what a user will see when visiting my website in IE8. They will see the same message if viewing in a browser that does not support csstransforms.

Screen Shot 2015 04 07 at 3 55 48 PM

Categorized In:

Learn Ruby on Rails For Free

I created Rails Code Along to help teach you how to build, test, troubleshoot, and launch a REAL production Rails application. This course is free, and does not require you to sign up.

Learn Ruby on Rails For Free

Let's Connect