A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/css/css-linear-gradient-function/ below:

CSS linear-gradient() Function - GeeksforGeeks

CSS linear-gradient() Function

Last Updated : 11 Jul, 2025

The linear-gradient() function is an inbuilt function in CSS that 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: 

The below examples illustrate the linear-gradient() function in CSS: 

Example 1: In this example, The .gradient element applies a linear gradient background from green to yellow to blue, with centered text on top.

html
<!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</h2>
    <div class="gradient">GeeksforGeeks</div>
</body>

</html>

Output: 

Example 2: The .gradient element applies a linear gradient background from right to left, with colors transitioning from green to yellow to blue.

html
<!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
    </h2>
    <div class="gradient">
        GeeksforGeeks
    </div>
</body>

</html>

Output: 

Supported Browser:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4