- CSS Gradients
- CSS Linear Gradients
- The linear-Gradient transition from Top to bottom
- The linear-gradient transition from left to right
- Linear-gradient diagonal transition
- CSS Radial Gradient
- Example (1) (Evenly Spaced Color)
- Example (2) (various-shaped color)
- The shape of the radial gradient
- Radial gradient Size
- Create a Rainbow transition in CSS
- CSS Gradient
In this advanced series of CSS tutorials, we will discuss how we can make a smooth transition between specified color using gradient values.
CSS Gradients
A gradient is a transition of two or more than two specified colors, and to create a transition, we can use the
background-image
property with the gradient value. There are two types of gradients
- Linear Gradients(up/down/left/right/diagonally)
- Radial Gradient (from the center)
CSS Linear Gradients
In linear gradients, the color transition can be moved from down to up, up to down, left to right, right to left, and diagonally. And to create a smooth transition gradient, we use the background-image property and
linear-gradient()
value. Inside the
linear-gradient(direction, color1,color2)
, we define the direction in which the transition should go and two or more colors.
Syntax
The linear-Gradient transition from Top to bottom
Top to bottom is the default value for the direction, in this color transition, change from top to bottom.
Example
Preview
The linear-gradient transition from left to right
When we want to set a colorful transition from left to right then, the linear-gradient direction must be set
to right
.
Syntax
Example
Preview
Note : To set the direction value to left from right to left transition or set the direction to up from bottom to up transition. Or use can Just reverse the order of the colors
Linear-gradient diagonal transition
To make a diagonal transition set the direction value
to bottom right
or
to bottom left
. This will present gradient colors in a diagonal direction.
Syntax
Example
Preview
CSS Radial Gradient
In the Radial gradient, the color transition starts from the center of the image. And like the linear-gradient, it also requires two or more than two colors to perform the smooth transition. But unlike the direction radial-gradient accept shape, size, and position for the transition.
- The default shape is an ellipse.
- The default size is farthest-corner
- The default position is the center.
Syntax
Example (1) (Evenly Spaced Color)
Preview
Example (2) (various-shaped color)
Preview
The shape of the radial gradient
By default, the shape of every radial transition is an ellipse but It can also be changed to circle.
Syntax
Example
Preview
Radial gradient Size
The size parameter specifies the size of the gradient, and it accepts 4 values.
- closest-side
- farthest-side
- closest-corner
- farthest-corner
Example
Preview
Create a Rainbow transition in CSS
We can either use the linear-gradient or radial-gradient to create a rainbow. But all the colors must be mention in the gradient parameter.
Example
Preview
CSS Gradient
- A gradient is a smooth transition of multiple colors.
-
To create a gradient, we use the
background-image
property. - A gradient could be linear or radial.
- The linear can create a color transition from left to right, top to bottom, or diagonally.
- The radial gradient creates a transition from center to corner.