Understanding CSS Linear Gradients
The CSS linear-gradient() function creates a color transition along a straight line. You specify a direction or angle, followed by two or more color stops. The browser smoothly interpolates between the colors. The simplest gradient — linear-gradient(#667eea, #764ba2) — transitions from top to bottom by default.
Angle System Explained
Gradient angles start at 0° (bottom to top) and rotate clockwise: 90° goes left to right, 180° top to bottom, 270° right to left. You can also use direction keywords like to right, to bottom left, or to top right. Diagonal gradients (45°, 135°) are popular for UI backgrounds because they add visual energy without being too aggressive.
Working with Multiple Color Stops
Add more than two color stops to create rich, layered gradients. Each stop can have a percentage position: linear-gradient(90deg, #ff0000 0%, #ffff00 50%, #00ff00 100%). Place two stops at the same position to create a hard edge. Stops without explicit positions are evenly distributed between their neighbors.