CSS Radial Gradients

CSS Radial Gradients

The radial gradient is defined by its center.

To create a radial gradient, you must also define at least two color stops.

Syntax

background-image: radial-gradient(shape size at position, start-color, ... , last-color);

By default,shape For elliptical,size For the farthest corner,position Centered.

Radial gradient - uniformly spaced color stops (default)

The following example demonstrates a radial gradient with uniformly spaced color stops:

Example

#grad {
  background-image: radial-gradient(red, yellow, green);

Try It Yourself

Radial gradient - color stops with different intervals

The following example demonstrates a radial gradient with different intervals between color stops:

Example

#grad {
  background-image: radial-gradient(red 5%, yellow 15%, green 60%);

Try It Yourself

Set shape

shape The parameter defines the shape. It can accept circle or ellipse values. The default value is ellipse (ellipse).

The following example demonstrates a circular radial gradient:

Example

#grad {
  background-image: radial-gradient(circle, red, yellow, green);

Try It Yourself

Use keywords with different sizes

size The parameter defines the size of the gradient. It can accept four values:

  • closest-side
  • farthest-side
  • closest-corner
  • farthest-corner

Example

Set different size keywords for radial gradients:

#grad1 {
  background-image: radial-gradient(closest-side at 60% 55%, red, yellow, black);

#grad2 {
  background-image: radial-gradient(farthest-side at 60% 55%, red, yellow, black);

Try It Yourself

Repeating Radial Gradient

repeating-radial-gradient() The function is used to repeat radial gradients:

Example

Repeating Radial Gradient:

#grad {
  background-image: repeating-radial-gradient(red, yellow 10%, green 15%);

Try It Yourself

CSS Gradient Properties

The following table lists the CSS gradient properties:

Attribute Description
background-image Set one or more background images for an element.