In the realm of CSS, linear gradients are a powerful tool for creating visually striking and dynamic backgrounds. One of the key aspects of working with linear gradients is understanding and controlling their direction. In this article, we'll delve into the world of CSS linear gradient direction, exploring its syntax, properties, and practical applications.
Understanding CSS Linear Gradients
Before we dive into the direction of linear gradients, let's quickly recap what they are. A linear gradient is a background image created by blending two or more colors along a straight line. This line is defined by the gradient's direction, which is what we'll be focusing on.
Here's a basic syntax of a linear gradient:

background: linear-gradient(direction, color1, color2, ...);
Defining the Direction
The direction of a linear gradient is defined by an angle, specified in degrees. The angle is measured clockwise from the positive x-axis (the top of the browser window).
For example, an angle of 0deg creates a gradient that flows from left to right, while an angle of 90deg creates a gradient that flows from top to bottom.
Direction Keywords
CSS also provides several keywords that can be used to set the direction of a linear gradient:

- to bottom: 90deg
- to top: 90deg (opposite direction)
- to right: 0deg
- to left: 180deg
- to bottom left: 135deg
- to bottom right: 45deg
Creating Complex Gradients
You can also create more complex gradients by combining multiple colors and directions. Here's an example:
background: linear-gradient(120deg, red, yellow), linear-gradient(60deg, green, blue);
The above code creates a gradient that flows from red to yellow at a 120deg angle, and another gradient that flows from green to blue at a 60deg angle. The result is a complex, multi-directional gradient.
Gradient Positioning
In addition to the direction, you can also control where the gradient starts and ends. This is done using the background-position and background-size properties.

| Property | Description |
|---|---|
background-position |
Sets the starting point of the gradient. |
background-size |
Sets the size of the gradient. Can be used to create repeating gradients. |
Browser Support
Linear gradients are widely supported in modern browsers, including Chrome, Firefox, Safari, and Edge. However, for maximum compatibility, it's a good idea to include a fallback for older browsers that don't support gradients.
Here's an example of a fallback using a solid color:
background: #f0f0f0;
background: linear-gradient(120deg, red, yellow);
In this example, if the browser doesn't support linear gradients, it will fall back to using a solid color background of #f0f0f0.






















