CSS | linear-gradient() Function

The linear-gradient() function is an inbuilt function in CSS which is used to set the linear gradient as the background image.

Syntax:

background-image: linear-gradient( direction, color1, color2, ... )

Parameters: This function accepts one direction parameter and many color parameters which are listed below:



  • direction: This parameter is used to define the starting point and direction along with the gradient effect.
  • color1, color2, …: This parameter is used to hold the color value followed by its optional stop position.

Below examples illustrate the linear-gradient() function in CSS:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>linear-gradient function</title>
        <style>
        .gradient {
            height: 100px;
            background-image: linear-gradient(green, yellow, blue);
            Text-align:center;
            padding-top:40px;
            font-size:40px;
            color:white;
            font-weight:bold;
        }
        h2 {
            text-align:center;
        }
        </style>
    </head>
    <body>
        <h2>linear-gradient: Top to Bottom property</h1>
        <div class="gradient">GeeksforGeeks</div>
    </body>
</html>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>linear-gradient function</title>
        <style>
        .gradient {
            height: 100px;
            background-image: linear-gradient(to left, green, yellow, blue);
            Text-align:center;
            padding-top:40px;
            font-size:40px;
            color:white;
            font-weight:bold;
        }
        h2 {
            text-align:center;
        }
        </style>
    </head>
    <body>
        <h2>linear-gradient: Right to Left property</h1>
        <div class="gradient">GeeksforGeeks</div>
    </body>
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.