[codepenembed height=”300″ themeid=”16787″ slughash=”doreEN” defaulttab=”result” user=”brandonhimpfen”]See the Pen Top to Bottom Linear Background Gradient by Brandon Himpfen (@brandonhimpfen) on CodePen.[/codepen_embed]The following Sass mixin will create a vertical background gradient, also known as a top to bottom (or bottom to top) background gradient.

// Vertical (Top to Bottom) Background Gradient
// See: http://www.himpfen.com/vertical-background-gradient-sass-mixin/
// Usage: @include bg-gradient-vertical(start, bottom);
// Example: @include bg-gradient-vertical(#fff, #000);
@mixin bg-gradient-vertical($start-colour, $end-colour) {
    background-color: $start-colour;
    background-image: -webkit-gradient(linear, left top, left bottom, from($start-colour), to($end-colour));
    background-image: -webkit-linear-gradient(top, $start-colour, $end-colour);
    background-image:    -moz-linear-gradient(top, $start-colour, $end-colour);
    background-image:     -ms-linear-gradient(top, $start-colour, $end-colour);
    background-image:      -o-linear-gradient(top, $start-colour, $end-colour);
    background-image:         linear-gradient(top, $start-colour, $end-colour);
    filter:            progid:DXImageTransform.Microsoft.gradient(start-colourStr='#{$start-colour}', end-colourStr='#{$end-colour}');
}

To use the vertical background gradient Sass mixin, include the following:

@include bg-gradient-vertical(start, bottom);

Where start is the starting colour (top) and end is the ending colour (bottom).

Example:

@include bg-gradient-vertical(#fff, #000);