Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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.
Advertisements
