Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. linear-gradient()

linear-gradient()

Specifies a linear gradient for the background. Use it as the value of the 'background' property.

Older browser versions may require vendor prefixes ('webkit', 'moz', 'ms', etc.) for gradients to work, so it is safer to include them.

For a radial gradient, use 'radial-gradient' instead of 'linear-gradient'. To apply gradients in IE9 and earlier, use 'filter'.

Sample Code

background: linear-gradient(#FFFFFF, #C9C9C9);
background: -webkit-linear-gradient(#FFFFFF, #C9C9C9);
background: -mozlinear-gradient(#FFFFFF, #C9C9C9);
background: -ms-linear-gradient(#FFFFFF, #C9C9C9);

Refer to the table below for which browser versions require vendor prefixes.

BrowserVersions requiring a vendor prefix
ChromeChrome 25 and earlier
SafariSafari 6 and earlier
FirefoxFirefox 16 and earlier
AndroidAndroid 5.0 and earlier
iOSiOS 6.1 and earlier

Browser Display Result

background: linear-gradient(#FFFFFF, #C9C9C9);
background: -webkit-linear-gradient(#FFFFFF, #C9C9C9);
background: -mozlinear-gradient(#FFFFFF, #C9C9C9);
background: -ms-linear-gradient(#FFFFFF, #C9C9C9);
height: 150px;

Browser Compatibility

Chrome Chrome
26+
25
24
23
22
21
20
19
18
↑ Requires prefix '-webkit-'
9 and earlier ×
Firefox Firefox
16+
15
14
13
12
11
10
9
8
↑ Requires prefix '-moz-'
2 and earlier ×
Safari Safari
7+
6
↑ Requires prefix '-webkit-'
4 and earlier ×
Edge Edge
12+
Supported in all versions
IE IE
11
10
9 ×
8 ×
7 ×
6 ×
Opera Opera
12.1+
11
↑ Requires prefix '-o-'
10 and earlier ×
iOS Safari iOS Safari
7+
6
5
↑ Requires prefix '-webkit-'
4 and earlier ×
Android Android Browser
4.4+
3 and earlier ×
Chrome Android Chrome Android
Latest
Same support as desktop
Firefox Android Firefox Android
Latest
Same support as desktop

※ Version data is based on MDN / Can I Use.

※ Android 5.0 and later support gradients without a vendor prefix. Android 4.x and earlier require a vendor prefix.

Details

Specifies a linear gradient for the background. The syntax is:
'linear-gradient(start-position angle, start-color, mid-color, end-color)'.
The start position, angle, and mid-color are all optional. When omitted, the default start position is 'top', the angle is '0deg', and no mid-color is set.

The example above shows a top-to-bottom gradient, but you can also specify a horizontal or diagonal gradient using the start position.

Without vendor prefixes, the start position must be specified from the opposite direction using 'to', e.g., 'to right'.

background: -moz-linear-gradient(left, #ffffff, #C9C9C9);
background: -webkit-linear-gradient(left, #ffffff, #C9C9C9);
background: -ms-linear-gradient(left, #ffffff, #C9C9C9);
background: linear-gradient(to right, #ffffff, #C9C9C9); /* Without vendor prefix, specify 'to right' to draw from left to right. */
height: 150px;

For a diagonal gradient, specify the angle in degrees ('deg'). The angle rotates counterclockwise with vendor prefixes.

Note: without vendor prefixes, the rotation direction is clockwise, not counterclockwise. For example, to get the same angle as '45deg' with vendor prefixes, you need to specify '135deg' without them.

background: -moz-linear-gradient(45deg, #ffffff 0%, #C9C9C9 100%);
background: -webkit-linear-gradient(45deg, #ffffff 0%, #C9C9C9 100%);
background: -ms-linear-gradient(45deg, #ffffff 0%, #C9C9C9 100%);
background: linear-gradient(135deg, #ffffff 0%, #C9C9C9 100%);
height: 150px;

You can create multi-color gradients by adding mid-colors, separated by commas. Optionally specify each color's position after the color value separated by a space.

background: -moz-linear-gradient(#ff0000 0%, #ffff00 40%, #ffff00 60%, #0000ff 100%);
background: -webkit-linear-gradient(#ff0000 0%, #ffff00 40%, #ffff00 60%, #0000ff 100%);
background: -ms-linear-gradient(#ff0000 0%, #ffff00 40%, #ffff00 60%, #0000ff 100%);
background: linear-gradient(#ff0000 0%, #ffff00 40%, #ffff00 60%, #0000ff 100%);
height: 150px;

Color positions can also be specified in 'px' units, and colors can be specified using 'rgb()'. You can mix 'rgb()' and hex color codes in the same declaration.

background: -moz-linear-gradient(rgb(255,0,0) 0px, #ffff00 60px, #ffff00 90px, rgb(0,0,255) 150px);
background: -webkit-linear-gradient(rgb(255,0,0) 0px, #ffff00 60px, #ffff00 90px, rgb(0,0,255) 150px);
background: -ms-linear-gradient(rgb(255,0,0) 0px, #ffff00 60px, #ffff00 90px, rgb(0,0,255) 150px);
background: linear-gradient(rgb(255,0,0) 0px, #ffff00 60px, #ffff00 90px, rgb(0,0,255) 150px);
height: 150px;

You can also overlay a gradient on top of a background image.

background: -moz-linear-gradient(rgba(246, 255, 0, 0.6), rgba(255, 0, 161, 0.6)), url(dictionary-css/img/sample.jpg);
background: -webkit-linear-gradient(rgba(246, 255, 0, 0.6), rgba(255, 0, 161, 0.6)), url(dictionary-css/img/sample.jpg);
background: -ms-linear-gradient(rgba(246, 255, 0, 0.6), rgba(255, 0, 161, 0.6)), url(dictionary-css/img/sample.jpg);
background: linear-gradient(rgba(246, 255, 0, 0.6), rgba(255, 0, 161, 0.6)), url(dictionary-css/img/sample.jpg);
width: 300px;
height: 200px;

If you find any errors or copyright issues, please .