5/15/2012 - 9:13 AM

Gradient Mixin - SASS/SCSS - Cross Browser

Gradient Mixin - SASS/SCSS - Cross Browser

@mixin linear-gradient($fromColor, $toColor) {
  background-color: $toColor; /* Fallback Color */
  background-image: -webkit-gradient(linear, left top, left bottom, from($fromColor), to($toColor)); /* Saf4+, Chrome */
  background-image: -webkit-linear-gradient(top, $fromColor, $toColor); /* Chrome 10+, Saf5.1+, iOS 5+ */
  background-image:    -moz-linear-gradient(top, $fromColor, $toColor); /* FF3.6 */
  background-image:     -ms-linear-gradient(top, $fromColor, $toColor); /* IE10 */
  background-image:      -o-linear-gradient(top, $fromColor, $toColor); /* Opera 11.10+ */
  background-image:         linear-gradient(top, $fromColor, $toColor);
  filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='$fromColor', EndColorStr='$toColor');

/* Usage - Stick into the top of your SCSS sheet and @include where needed for cross browser linear gradients. 

.class {
    @include linear-gradient(#color, $color);


Can pass Hex values or indeed a variable color if required.

Usage example;


$myColor: red; // not required unless using variable.

.item {
    @include linear-gradient(#BADA55, $myColor);


IE9 Support (idea courtesy of )

Support for full multi-stop gradients with IE9 (using SVG).

Add a "gradient" class to all your elements that have a gradient, and add the following override to your HTML to complete the IE9 support:

<!--[if gte IE 9]>
  <style type="text/css">
    .gradient {
       filter: none;