Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!

The CSS radial-gradient() function creates an <image> which represents a gradient of colors radiating from an origin, the center of the gradient. The result of this function is an object of the CSS <gradient> data type.

Radial gradients are defined by their center, the ending shape contour and position, and color stops. The radial gradient consists, going from its center to its ending shape and potentially beyond, of successive uniformly-scaled concentric shapes, identical to the ending shape. Color stops are positioned on a virtual gradient ray going out horizontally of the center to the right. Percentages positioning of color stops are relative to the intersection between the ending shape and this gradient ray representing 100%. Each shape is monocolor and defined by the color on the gradient ray it intersects.

Ending shapes can only be circle or ellipse.

Like any other gradient, a CSS radial gradient is not a CSS <color> but an image with no intrinsic dimensions, i. e. it has no natural or preferred size, nor ratio. Its concrete size will match the one of the element it applies to.

The radial-gradient function does not allow repeating gradients. For such a functionality, use the CSS repeating-radial-gradient() function.

Syntax

// Definition of the ending shape
radial-gradient( circle, … )                /* Synonym of radial-gradient( circle farthest-corner, … ) */
radial-gradient( ellipse, … )               /* Synonym of radial-gradient( ellipse farthest-corner, … ) */
radial-gradient( <extent-keyword>, … )      /* It draws a circle */
radial-gradient( circle radius, … )         /* A centered circle of the given length. It can't be a percentage */
radial-gradient( ellipse x-axis y-axis, … ) /* The two semi-major axes are given, horizontal, then vertical */

// Definition of the position of the shape
radial-gradient ( … at <position>, … )

// Definition of the color stops
radial-gradient ( …, <color-stop>, … )
radial-gradient ( …, <color-stop>, <color-stop> )

Values

<position>
A <position>, interpreted in the same way as background-position or transform-origin. If omitted, the default is center.
<shape>
The gradient's shape. This is one of circle (meaning that the gradient's shape is a circle with constant radius) or ellipse (meaning that the shape is an axis-aligned ellipse). The default value is ellipse.
<color-stop>
Representing a fixed color at a precise position, this value is composed by a <color> value, followed by an optional stop position (either a <percentage> or a <length> along the virtual gradient ray). A percentage of 0%, or a length of 0, represents the center of the gradient, the value 100% of the intersection of the ending shape with the virtual gradient ray. Percentage values in-between are linearly positioned on the gradient ray.
<extent-keyword>
Keywords describing how big the ending shape must be. The possible keywords are:
Constant Description
closest-side The gradient's ending shape meets the side of the box closest to its center (for circles) or meets both the vertical and horizontal sides closest to the center (for ellipses).
closest-corner The gradient's ending shape is sized so it exactly meets the closest corner of the box from its center.
farthest-side Similar to closest-side, except the ending shape is sized to meet the side of the box farthest from its center (or vertical and horizontal sides).
farthest-corner The gradient's ending shape is sized so it exactly meets the farthest corner of the box from its center.
Early drafts included other keywords (cover and contain) as synonyms of the standard farthest-corner and closest-side respectively. Use the standard keywords only, as some implementations have already dropped those older variants.

Formal syntax

radial-gradient(
  [ [ circle || <length> ]                         [ at <position> ]? , |
    [ ellipse || [ <length> | <percentage> ]{2} ]  [ at <position> ]? , |
    [ [ circle | ellipse ] || <extent-keyword> ]   [ at <position> ]? , |
    at <position> ,
  ]?
  <color-stop> [ , <color-stop> ]+
)
where <extent-keyword> = closest-corner | closest-side | farthest-corner | farthest-side
  and <color-stop>     = <color> [ <percentage> | <length> ]? 

Example 1

Using the following CSS we can get an ellipse background in the farthest-corner at 45px 45px, changing color from Turquoise (#00FFFF), to White, to Blue (#0000FF):

body {
  width: 100vh;
  height: 100vh;
  background-image: radial-gradient(ellipse farthest-corner at 45px 45px , #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);
} 

Example 2

This will procude an ellipse background in the farthest-corner at 470px 45px, changing color from Yellow (#FFFF80), to Pale Maroon, to Pale Blue (#E6E6FF):

body {
  width: 100vh;
  height: 100vh;
  background-image: radial-gradient(ellipse farthest-corner at 470px 47px , #FFFF80 20%, rgba(204, 153, 153, 0.4) 30%, #E6E6FF 60%);
}

Example 3

This will procude an ellipse background in the farthest-corner at 45px 45px, changing color from Red (#FF0000) to Blue (#0000FF):

body {
  width: 100vh;
  height: 100vh;
  background-image: radial-gradient(farthest-corner at 45px 45px , #FF0000 0%, #0000FF 100%);
}

Example 4

This will procude a fuzzy circle with a 16px radius:

body {
  width: 100vh;
  height: 100vh;
  background-image:  radial-gradient(16px at 60px 50% , #000000 0%, #000000 14px, rgba(0, 0, 0, 0.3) 18px, rgba(0, 0, 0, 0) 19px); 
} 

Specifications

Specification Status Comment
CSS Image Values and Replaced Content Module Level 3
The definition of 'radial-gradients()' in that specification.
Candidate Recommendation Initial definition

Browser compatibility

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support (on background and background-image) 3.6 (1.9.2)-moz[1]
16 (16)
10.0 (534.16)-webkit[2] 10.0[3] 11.60-o 5.1-webkit[2]
On border-image 29 (29) (Yes) (Yes) (Yes) (Yes)
On any other property that accept <image> No support (Yes) (Yes) (Yes) (Yes)
Legacy webkit syntax No support 3-webkit[2] No support No support 4.0-webkit[2]
at syntax (final standard syntax) 10 (10)-moz[1]
16 (16)[4]
26 10.0 11.60-o[2]
2.12
No support
Interpolation hints (a percent without a color) 36 (36) 40   27  
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (on background and background-image) (Yes) 1.0 (1.9.2)-moz[1]
16.0 (16)
10 (Yes) (Yes)
On border-image (Yes) 29.0 (29) (Yes) (Yes) (Yes)
On any other property that accept <image> No support (Yes) (Yes) (Yes) (Yes)
Legacy webkit syntax ? No support ? ? ?
at syntax (final standard syntax) ? 10.0 (10)-moz[1]
16.0 (16)
10 ? ?

[1] Firefox 3.6 implemented, prefixed, an early syntax. Before Firefox 36, Gecko didn't apply gradient on the pre-multiplied color space, leading to shade of grey unexpectedly appearing when used with transparency. Since Firefox 42, the prefixed version of gradients can be disabled by setting layout.css.prefixes.gradients to false.

[2] Webkit implemented, prefixed, an early syntax. WebKit since 528 supports the legacy -webkit-gradient(radial,…) function. See also their current support for radial gradients.

[3] Internet Explorer 5.5 through 9.0 supports proprietary filter: progid:DXImageTransform.Microsoft.Gradient() filter.

[4] In addition to the unprefixed support, Gecko 44.0 (Firefox 44.0 / Thunderbird 44.0 / SeaMonkey 2.41) added support for a -webkit prefixed version of the function for web compatibility reasons behind the preference layout.css.prefixes.webkit, defaulting to false. Since Gecko 49.0 (Firefox 49.0 / Thunderbird 49.0 / SeaMonkey 2.46) the preference defaults to true.

See also