CSS lets you set the background of your web page using the background-image
property. You can add it in the form of a picture or you can customize it. One possible example of a custom-built CSS background could be CSS gradient.
A gradient is a blend of colors in which one color gradually changes into another. Gradient backgrounds were introduced in CSS3
which lets you add gradient backgrounds and also allows you to set the color, shape, and transparency of the gradient through different methods.
CSS has two types of gradients:
In a linear gradient, you define at least two colors and a direction in which the color will transition. So, basically you need to pass three parameters:
linear-gradient(direction, color1, color2)
Let’s create a linear gradient in which the color yellow transitions into green from right to left.
Tip:
rgba()
method is used to add transparency in your gradient. The last parameter of this method can be set to any value between 0 and 1 which defines the intensity of transparency where 0 being the highest and 1 being the lowest.
In a radial gradient, the color transitions from the center towards the edge of the pages. The parameters that we pass in the radial-gradient()
method are almost the same with one addition though. Here, we can also specify the shape of the gradient.
radial-gradient(shape size, color1 position, color2 position, ...);
These are all the parameters that you need to pass in a radial-gradient()
method:
The example below creates a radial gradient starting from grey at 0%, to yellow at 20% to green at 60% and then finally white at 80% till 100%.
Fact: There is a website called CSS Gradient that lets you create gradients of your choice of colors and provides a variety of other customization options!
Free Resources