CSS3 Left to right Gradient

CSS3 left to right gradient creates a smooth color transition that flows horizontally from the left edge to the right edge of an element. This is achieved using the linear-gradient() function with the to right direction.

Syntax

selector {
    background: linear-gradient(to right, color1, color2, ...);
}

Example: Basic Left to Right Gradient

The following example creates a red to blue gradient flowing from left to right −

<!DOCTYPE html>
<html>
<head>
<style>
    .gradient-box {
        height: 100px;
        width: 300px;
        background: linear-gradient(to right, red, blue);
        border: 1px solid #ccc;
        margin: 20px 0;
    }
</style>
</head>
<body>
    <div class="gradient-box"></div>
</body>
</html>
A horizontal rectangle with a smooth gradient transition from red on the left to blue on the right appears on the page.

Example: Multi-Color Gradient

You can create gradients with multiple colors by adding more color stops −

<!DOCTYPE html>
<html>
<head>
<style>
    .multi-gradient {
        height: 100px;
        width: 300px;
        background: linear-gradient(to right, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4);
        border: 1px solid #ccc;
        margin: 20px 0;
    }
</style>
</head>
<body>
    <div class="multi-gradient"></div>
</body>
</html>
A horizontal rectangle displaying a smooth gradient transition through four colors: coral red, teal, blue, and mint green from left to right.

Conclusion

CSS3 left to right gradients provide an elegant way to create horizontal color transitions. Use linear-gradient(to right, color1, color2) for smooth visual effects in modern web designs.

Updated on: 2026-03-15T12:03:33+05:30

257 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements