Introduction
Continuing further from the previous Using Border Radius and Gradients in CSS3: Part I article, where we saw a basic introduction to using gradients, in this article, we will see how to use more complex gradients. Let's take an example of a linear gradient again.
Create the following HTML file and save it as index.html.
Index.html
This HTML file is identical to the one created in the previous article. The only change will be the styles we apply. Save the following code in a file named style.css under the css folder.
css/style.css
Similar to the earlier example, here too, care is taken to include code that will work on multiple browsers instead of catering to just one. Again when you view the HTML file in various browsers, you will find identical output everywhere similar to the one shown below.
![img1.jpg]()
This colorful effect has been achieved using a combination of a start color, and end color and some color stops in between. A color stop is an in-between value and has a color and a position. When the browser fades the color from one stop to the next stop, a smooth multi-color effect is created, thus resulting in a gradient.
You can tweak or fine-tune the various values in the background-image property shown above until you get the color effect you are looking for. Alternatively, instead of using only hexadecimal color codes, you can also work with decimal color codes, that is, the RGB color combination.
This will result in an output similar to the below.
![img2.jpg]()
In all the examples so far, we have used gradients with background colors. However, the use of gradients need not be confined to background alone. You can use them in borders, lists, and other elements wherever applicable. However, as of now, browser support for such borders is limited.
Of course, if you are too lazy or don't have time to sit and churn out the various codes required to create a gradient, you can use ready-made tools.
Conclusion
This article explored further ways of working with gradients.