CSS Gradients


In CSS, a gradient is a type of image that consists of a progressive and smooth transition between two or more colors. CSS is a method for adding style to various web documents. Using the gradient in CSS, we can create image styling variants that can aid in the creation of an appealing webpage.


1. Linear Gradients:

These are color transitions that go up, down, left, right, and diagonally. A two-color minimum is required to create a linear gradient. Linear gradients can have more than two color elements. The gradient effect requires a starting point and a direction.

Syntax


The linear-gradient can be implemented in the following ways:

Top to Bottom:

The transition in this image began with white and ended with green. When the color sequence is switched, the transition will begin with green and end with white.

Example

Preview

Left to Right:

The transition in this image began on the left. It begins with white and progresses to green.

Example

Preview

Diagonal:

This transition ran diagonally from top-left to bottom-right. It begins with a green transition to a white background. It is necessary to specify both horizontal and vertical starting positions for the diagonal gradient.

Example

Preview

Repeating Linear Gradient:

CSS allows the user to implement multiple linear gradients using a single function repeating-linear-gradient (). Each transition in this image has three colors with a percentage value.

Example

Preview

Angles on Linear Gradients:

Instead of being limited to predefined directions, CSS allows users to implement directions in Linear Gradients.

Example

Preview

The radial-gradient can be implemented in several ways, including:

2. Radial Gradient:

By default, the fade occurs at an equal rate in CSS. The Radial Gradient with even color stops is depicted in the figure below.

Syntax


Radial Gradient evenly spaced color stops:

Color stops tell browsers what color to use, where to start the gradient, and where to stop. They are evenly spaced by default, but we can override this by specifying the specific color stops.

Example

Preview

Radial Gradient unevenly spaced color stops:

While using the radial-gradient feature, CSS allows the user to vary the spacing of color stops.

Example

Preview