Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteUse CSS’s linear-gradient() function as a background image. For a left-to-right blue-to-purple gradient, write:
.element {
background: linear-gradient(to right, #2563eb, #a855f7);
}
Change the direction, colors, and color-stop positions to control the result. A gradient is an image value, so use it with background or another property that accepts images—not background-color, which accepts a color.
How linear-gradient() works
The function creates an image whose colors transition along a line. Its first argument can set the line’s direction; the remaining arguments specify colors and, optionally, where each color appears. The W3C’s CSS Images Module Level 3 defines the first argument as the gradient line, which determines its direction and the positioning of color stops.
A gradient has no intrinsic dimensions. It is drawn within the box where the image is used, so the element’s dimensions affect how the gradient appears. The basic pattern is:
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
background: linear-gradient(direction, color1, color2);
The direction is optional, but at least two colors are needed.
Set the gradient direction
Use side or corner keywords
If you omit the direction, the gradient runs downward, from the top of the element to the bottom. Use to followed by a side or corner to choose another direction:
.right {
background: linear-gradient(to right, #2563eb, #a855f7);
}
.diagonal {
background: linear-gradient(to bottom right, #2563eb, #a855f7);
}
Other examples include to top and to left. Direction keywords describe where the gradient is headed; to right means it moves from left to right.
Rank #2
Use an angle
Angles provide more precise control. CSS gradient angles start at upward: 0deg points up, and positive values turn clockwise. That means 90deg points right, 180deg points down, and 270deg points left.
.angled {
background: linear-gradient(135deg, #f97316, #7c3aed);
}
Choose a keyword for a direction that reads naturally, or an angle when you want a specific slant. For a practical guide to gradients and their direction, see MDN’s guide to using CSS gradients.
Position colors with stops
Color stops determine which colors appear and where transitions happen. If you leave stop positions out, the first and last colors anchor the ends and any intervening unpositioned colors are distributed between their neighboring stops.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
.banner {
background: linear-gradient(
90deg,
#0f172a 0%,
#2563eb 55%,
#e0f2fe 100%
);
}
Here, the middle color is placed at 55% along the gradient line. Positions may be percentages or lengths. Adjusting them changes the portions of the gradient occupied by each color and the location of each transition.
Create a hard edge
Give two different colors the same stop position to create a sharp boundary instead of a gradual blend. For a two-color split, specify the beginning and end positions of each color:
.stripe {
background: linear-gradient(90deg, #2563eb 0 50%, #f97316 50% 100%);
}
Both colors meet at 50%, so there is no blended band between them. This is useful for stripes, blocks, or a two-tone background.
Rank #4
Shift the transition midpoint
A percentage color hint between two color stops can shift where the transition reaches its midpoint. A hint changes the distribution of the blend between those colors; it is not an extra color stop.
Repeat a gradient pattern
Use repeating-linear-gradient() when the pattern should repeat across the image. The distance between its first and last stop sets the repeating segment. If the colors at the segment boundary differ, the repeat can create a hard seam; matching the boundary colors allows a continuous transition across repetitions.
.pinstripe {
background: repeating-linear-gradient(
45deg,
#1d4ed8 0 8px,
#dbeafe 8px 16px
);
}
This example repeats alternating 8-pixel color bands. For the function’s syntax, see MDN’s repeating-linear-gradient() reference.
Best Value
Use newer color-space interpolation carefully
CSS Images Module Level 4 adds optional color-interpolation syntax. For example, linear-gradient(90deg in oklab, blue, red) specifies the oklab color space for interpolation; hsl is another possible choice. This is distinct from the basic gradient syntax, and newer interpolation options are not implemented in every browser. Check support for the browsers you target before depending on one. The specification is documented in the W3C CSS Images Module Level 4. MDN describes basic linear-gradient() as widely available since July 2015, but that broad support statement does not guarantee support for every newer interpolation feature. See the MDN linear-gradient() reference.
Common problems and fixes
- The gradient does not appear: Check that you assigned it to an image-accepting property such as
background.background-coloraccepts a color, not a gradient image. - The direction seems reversed or unexpected: Remember that the default runs downward. For angles, zero points up and positive angles rotate clockwise; use
to rightfor a left-to-right gradient. - The transition is not where you want it: Set explicit stop positions, then adjust them. Unpositioned stops are distributed between their neighboring stops.
- You wanted a solid boundary, but got a blend: Give the adjacent colors the same stop position.
- The repeated pattern has an unwanted seam: Check the first and last colors at the repeat boundary. Different colors there make a hard seam.
- A newer interpolation form fails in a target browser: Use the basic gradient syntax or another supported form, and verify the newer feature against the browsers you need to support.
Or skip the browser setup
If you need a screenshot of a page with your gradient, ScreenshotNeo can return an image or PDF from one API request. Its clean-shot steps can accept cookie or consent banners and remove 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. An MCP server also lets AI agents use take_screenshot, get_page_info, and capture_pdf.
Example request (replace the URL with your page and provide your API key):
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




