Miguel Rodríguez does effective software development.

Things you should do to support CSS3

Technology has changed the life of everyone, especially internet, lately, there are available a new generation of internet browsers with new features that let create rich internet apps and awesome websites, they provide tools for connectivity, presentation, performance and much more. But there is a problem, people who do not update their browsers, this is making the use of CSS3 challenging, but does this mean that using CSS3 is discouraged?, of course not, there are a couple of things that you can do in order to use it.
 

Before start, check it out in caniuse.com

 
Before saying anything, it is important that you know exactly what you are going to do, I mean with "exactly" that you must know previously every style, shape, layout and animation that you will use in your design, because you must check every single feature that you are going to use, this is really important, you can not skip this step, if you rely too much on a feature that is available just for a few browsers, you will have a big problem, because there will be no way that you can support those other browsers.
I strongly encourage to check every single feature that you are going to use on caniuse.com, this is a website with a thorough description of every single CSS3 feature with its respective table support, there are also websites like html5please.com that shows a description for a lot of CSS3 features, occasionally with their advices.
 

Use Modernizr

 
One way to support browsers that can not handle some CSS3 features is to set a fallback, simply if the given feature is not available you will use another feature instead, it is not necessary to use an special library to set a fallback in the most of the cases, but if you want to give a better support it will be necessary that you use Modernizr.
Modernizr is a JavaScript library that will check every CSS3 feature available, it provides JavaScript methods and CSS classes to give a way to apply actions depending on the features available, it is based on YepNope, and  it is pretty handy, and I would say, necessary, I would also say if you are willing to use CSS3 then you will have to use Modernizr, it loads at the beginning and it will not interfere with any other thing, even the performance, when you use Modernizr the HTML element (<html>) will have a couple of CSS classes with the supported and unsupported features, letting you to define the CSS3 code per case, like this:
  1. .cssanimations.csstransforms3d #element{
  2. /*code here*/
  3. }
  4.  
  5. .no-animations.csstransitions.csstransforms #element{
  6. /*code here*/
  7. }
For example, this code will check if CSS3 animations and 3D transforms are available, if not it will check if CSS3 transitions and 2D transforms are available, maybe it can arise situations that you must set this kind of validations, if something is not available you will use something that looks pretty much the same, as you can see, using Modernizr is pretty simple, it will ease you of doing all that detection all for yourself.
 

Use polyfills

 
A polyfill is an alternative solution for a feature in order to support older browsers, There are a lot of polyfills available for any purpose, there are plenty of them for IE (of course, this is the browser that gives more problems), and the most of them work with HTML Components (only works on IE), they will provide you an HTC file that you must load in a CSS property called "behavior", something like this:
  1. #element{
  2. /*CSS3 unsupported code here*/
  3. behavior:url(/file.htc);
  4. }
This file must be used at the bottom of each CSS block using unsupported features (you may like to use Modernizr here), once loaded, the CSS3 code will work as usual. These HTC files must be accessible each time it is being used, making the file available directly through the server is the best option, you can set an Alias in the server if you are working with Apache.
  1. Alias "/file.htc" "/path2file/file.htc"
You must do this for every polyfill that require to load a HTC file. In some cases, there might exist extensions, modules, or similar, offering a way to load these HTC files without doing this (I have seen these modules on Drupal before), installing these modules is highly discouraged, they will only add code for nothing, we are going to see some polyfills that might help to support CSS3 on IE.
 

CSS3PIE

This is one of the most useful polyfills I have ever seen, it support a lot of CSS3 features for older browsers, it supports box-shadow, border-image, border-radius and rgba colors, features that are widely used in internet. The way to install it and use it is the same as above, they will give a HTC file, you will load it in your CSS code, and work as usual.
 

Box-sizing polyfill

If you are going to use border-image then I strongly suggest to use Box-sizing polyfill, this polyfill will support box-sizing for older browser, there are situations when you use a border (either thin or thick) the container of the information may measure more than it is expected, that could look bad or even can break the layout (e.g.: if there are floating DIVs with a percentile fix width next to each other, just as if it was a row, and one of those has a border, it can make one of the other containers fall down to the other row), this polyfill provides an HTC file that you must use in you CSS code (as I mention before).
 

Be aware of CSS3 Features harder to support

 
Unfortunately, there are some features that are really hard to support for older browser, some others have a questionable performance (I am not saying bad, just questionable) and you should be aware of this before trying to use one of these features.
 

Border-image with 'repeat' scheme

Sadly, there are no polyfills that can support this feature, they only support border-image with 'stretch' scheme, I was a victim of this too, but if you ever need to support this feature for older browser, you have replace the borders with DIVs and restructure the HTML in a way that the DIVs look like the border you are searching for.
Warn style
Attribution: 
This picture is showing one of the styles it was defined in the CSS code of this website, this style is simply not supported for Internet Explorer, there are neither no polyfills available to solve this problem nor fallback it can be applied. In this case, the only solution I could found for this problem is not using this style and restructuring the HTML in the sections that I had to apply this style, for example, I had to apply this style to the highlighted section (the opening door section), the solution was to put two DIVs that look like the borders I wanted to put, like this.
 
Border-image with &#039;repeat&#039; scheme (Workaround, CSS)
Alternative solution to support border-image with 'repeat' scheme on IE.
Attribution: 
There might exists other cases where applying this style is impossible, unless you do not want to support older browsers, this is something that you should be aware of before doing anything with CSS3.
 

Box-shadow

There are polyfills supporting this feature, but it is not fully supported, the performance is (obviously) not the same to the browsers that support CSS3 natively, additionally, there are a couple of things that no polyfill can do.
  • Inner shadow: There are no polyfills supporting this feature (by now), inner shadows can be very useful, especially if you change the color of the shadow, this is used to make good-looking buttons and many other things. There are things that you can do depending on the situation, you can set a fallback to the box-shadow, or you can replace the entire shadow with something similar, anyway, the solution is to replace the whole shadow, for example, each button of this template has been made with an light upper inner shadow and a dark lower inner shadow, this makes the button looks like a button, if the browser does not support inner shadows, it will replace the shadows with a light upper border (with a color similar to the button) and a dark lower border.
Buttons (Shadows, CSS3)
Attribution: 
Using a border to replace those shadows is a pretty simple idea that works, it is still well-look button without having to do anything special, but there are other cases that the best solution is not using inner shadows.
Inner shadow workaround
Alternative solution to support inner shadows on IE.
Attribution: 
If you have to place an Internal shadow to a container the best solution is to put objects in the container so their shadows will make the container look as if it has internal shadow, there is no other way (or at least I could not found another alternative), although is not that simple, it does not look bad, we might say it looks good and we are solving the problem anyway, but it might get worst depending on what you are going to do, be aware that supporting box-shadow is not simple, I encourage you to know exactly what you have to do and check if you can really do it.
  • Unexpected behavior: The shadow may have not the same transparency than the native browsers (in fact, it is opaque), the shadow it is more like an object, therefore, the shadow has not a natural look, depending on the position of the element generating the shadow, the shadow may overlap another element making it unclickable, you should be aware that it might have not the same performance and stability as native browsers (I am blaming Internet Explorer, not the polyfills).
 

CSS3 Animation/Transition performance issues

HTML5 and CSS3 are being developed and improved day by day, but, the support and performance for each browser is not the same, that includes CSS3 animations and transitions, a well supported website is supposed to use each feature on each browser with a similar performance each other, there are some things that you should not do when animating with CSS3.
 
  • Animating big elements: Animating small elements is not the big deal, but there might be some browsers that its animating performance could worsen when animating bigger elements, perhaps dividing the animation into smaller pieces or animating smaller elements might be a better idea, there are some initiatives trying to implement better methods for animation such as RequestAnimationFrame, but those technologies are still immature, another way to solve the performance issues is to use an alternative such as canvas or SVG, although you could have the same problem if you are trying to animate bigger elements, the performance could get even worse if the animation involves the modification of multiple properties of that element being animated, the performance could get so bad that the result could be catastrophic, as I mention before, you should think about those things before doing anything.
  • Animation overload: all the browsers are really different from each other, therefore, they will handle the load differently, some of them are capable to handle big loads with an overall good performance, but, unfortunately that does not happen with all of them, large animations where everything is activated at the same time all the time unnecessarily can be so sluggish and clumsy that they are even capable to freeze some browsers, think as if the animation was a scene of a theater play, every actor has a role and a time to perform, the animation should work the same way, do not activate any element unnecessarily.
 

Latest advices

 
Unfortunately, no matter how hard you try you can not support every browser, almost all programs in the world work like this, they support a specific number of platforms, and if a newer program is released, just the newer and most used platforms will be supported, every web application should work like that (even websites, of course), besides, I do not think that updating a browser or installing a new one it is so hard, at present CSS3 is supported by a wide range of browsers of every platform, therefore, if you really want to use a new CSS3 feature, then use it in a way that all the browsers can display the website even if it does not look the same, of course this is just a personal thought, and I can not take the decision for you.

About me

About the author
Miguel Rodríguez is a freelance developer from Caracas - Venezuela. He is a persistent and goal-oriented person who tries to make the best use of the resources. He is positive, proactive and motivated enough to set a goal with the intention to fulfill it. Find more about him .