Web Gradient Background Colours: From Palette to CSS
Picking colours for a web gradient background is easy. Getting that gradient to look the same on your screen, your phone, and your colleague's ultrawide monitor is where most people get stuck. This guide walks you through choosing a palette, writing the CSS, and fixing the banding and muddy midpoints that make gradients look cheap.
Along the way you will see how a browser-based colour picker fits into the workflow, and why a web gradient background built from two nearby hues almost always beats one built from three distant ones.
What a Web Gradient Background Actually Is
A web gradient background is a CSS background image that blends two or more colours along a line, a circle, or an angle. The browser calculates every pixel between your colour stops. Nothing is downloaded, so a gradient costs no extra requests and scales to any screen size.
That last point matters more than it sounds. A gradient is resolution-independent. A JPEG hero image is not. If you replace a large photographic banner with a gradient, you cut page weight and remove a layout shift at the same time.
Two CSS functions do almost all the work:
linear-gradient()blends along a straight line you define with an angle or a keyword such asto right.radial-gradient()blends outward from a centre point, which suits spotlights and soft vignettes.
There is also conic-gradient(), which sweeps around a centre point. It is useful for colour wheels and progress rings, but it is a poor fit for page backgrounds because the seam is usually visible.
Stops, Angles, and Colour Space
A colour stop is a colour plus an optional position, written as #1b4b8f 40%. The browser blends from one stop to the next. If you omit positions, the stops spread evenly, which is rarely what you want on a wide layout.
The angle controls direction. 0deg points up, 90deg points right, and 180deg points down. Keywords such as to bottom right are easier to read and behave the same way.
One detail trips up almost everyone: the gradient box is the element's padding box, not the viewport. A gradient on a narrow container will compress differently from the same gradient on body.
How to Build a Web Gradient Background in Five Steps
- Decide the job the gradient does. A background behind long text needs low contrast. A hero band behind a headline can carry more saturation. Write this down before you open any tool, because it settles most later arguments.
- Pick two anchor colours and one accent. Two anchors define the blend. The accent is a mid-stop you add only if the blend looks flat. Most pages need two colours, not five.
- Check contrast before you fall in love with the palette. Sample the lightest and darkest points where text will sit. If body text drops below a comfortable contrast ratio against either end, darken the gradient or move the text.
- Write the CSS with explicit stop positions. Start with something like
linear-gradient(135deg, #0f2a4a 0%, #2f6f9f 100%), then adjust the percentages until the midpoint sits where you want it. - Test at three widths and in both colour schemes. Narrow, medium, and wide. Then flip your operating system to dark mode, because a gradient that looks calm on white can look washed out on black.
You can run steps two and three in a browser-based colour tool without installing anything. It will not tell you whether a palette suits your brand, and it cannot check contrast against text you have not placed yet. Those are still your calls.
How Do You Choose Colours That Blend Well?
Choose colours that sit close together on the colour wheel, then vary lightness rather than hue. A blend from a deep navy to a mid blue reads as intentional. A blend from navy to orange reads as a sunset, whether you wanted one or not.
Three rules cover most cases:
- Keep hue drift small. Under roughly 40 degrees of separation, blends stay clean.
- Push lightness further than feels necessary. Screen blends lose contrast in the middle.
- Avoid blending through grey. A straight line between two opposite hues passes through a desaturated midpoint, which is the muddy look people complain about.
If you do want a wide hue range, add a middle stop in a saturated colour. That pulls the blend away from grey and keeps the transition crisp.
Reading a Palette Before You Commit
A palette is just a set of colours with roles: background, surface, text, and accent. Gradients should draw from the background and surface roles only. If your accent colour ends up as a gradient stop behind a button, the button stops standing out.
Write your palette as hex values in one place. Scattered hex codes across a stylesheet are the main reason a gradient looks fine on one page and wrong on another.
Long-Tail Cases Worth Planning For
Gradient Background for a Landing Page Hero
A landing page hero carries a headline, a subhead, and usually a button. The gradient has to stay quiet behind all three. Use a low-contrast blend and place the brightest area away from the text.
Darken the gradient slightly behind the text block rather than adding a heavy overlay. A subtle second layer costs one line of CSS and keeps the colours readable.
CSS Gradient Background With Transparency
Transparency is how you layer a gradient over an image or a solid colour. Write colours with rgba() or eight-digit hex, where the last pair is the alpha channel. #0f2a4a80 is the same navy at fifty percent opacity.
Transparent gradients are the standard way to fade an image into a page background. They also let you reuse one gradient over several different base colours.
Smooth Gradient Background Without Banding
Banding shows up as visible steps between colours, usually on large, low-contrast blends. It happens because screens have limited colour depth and the blend crosses too few distinct values.
Three fixes, in order of effort:
- Shorten the blend so it crosses more colour values per pixel.
- Add a very subtle noise or grain layer at low opacity.
- Reduce the contrast between the two stops.
The third fix works best and costs nothing. If a gradient bands badly, the two colours were probably too far apart to begin with.
Accessible Gradient Background Behind Text
Accessibility here means contrast, not colour choice. Text over a gradient has to clear a contrast threshold against every point it overlaps, not just the average.
The practical approach is to test the extremes. Sample the lightest pixel under the text and the darkest, then check both. If either fails, either darken that end of the gradient or move the text off the gradient entirely.
Do not rely on a text shadow to rescue contrast. Shadows help, but they are not a substitute for a background that already works.
A Worked Example
Suppose you want a calm header band. Start with a deep teal and a lighter blue-green, roughly 30 degrees apart on the wheel.
.hero {
background-image: linear-gradient(135deg, #0b3b3c 0%, #1f7a72 100%);
}
That is a two-stop blend at a diagonal angle. It reads as a single colour family and stays quiet behind white text.
If the middle looks flat, add a stop rather than changing the endpoints:
.hero {
background-image: linear-gradient(135deg, #0b3b3c 0%, #14635f 55%, #1f7a72 100%);
}
The middle stop sits slightly darker than a straight blend would produce, which keeps the transition from washing out. Adjust the 55% until the darker region sits where your headline lands.
Common Mistakes
- Too many stops. Three is usually the ceiling. Past that, the blend stops reading as a gradient and starts reading as a stripe.
- Blending complementary hues. Opposite colours meet in the middle at grey. Add a saturated middle stop or pick closer colours.
- Ignoring the container. A gradient tuned on a 1400px container will look different in a 600px card.
- Forgetting dark mode. A gradient that works on white can glare on black.
- Hardcoding hex values everywhere. Keep them in one place so a palette change is one edit.
Frequently Asked Questions
What is the difference between a linear and a radial gradient?
A linear gradient blends along a straight line set by an angle or direction keyword. A radial gradient blends outward from a centre point in expanding rings. Linear suits page backgrounds, headers, and buttons. Radial suits spotlights, glows, and soft vignettes behind a focal element.
Can I use a web gradient background instead of an image?
Yes, and it is often the better choice. A gradient adds no download weight, scales to any resolution, and cannot cause a layout shift. The trade-off is that it cannot reproduce photographic detail. For texture or imagery you still need an image, though a gradient can sit on top of one.
Why does my gradient look different on my phone?
Screens vary in colour depth, brightness, and colour profile, so a subtle blend can look smoother or steppier depending on the device. Narrow viewports also compress the gradient into fewer pixels. Test on a real phone rather than trusting a resized desktop window.
How many colours should a gradient use?
Two for most backgrounds, three when the blend looks flat in the middle. Adding stops increases the chance of visible banding and makes the palette harder to maintain. If you need more than three, the design probably wants two separate elements rather than one gradient.
Does a gradient hurt page performance?
A simple CSS gradient is essentially free. The browser paints it during layout with no network request. Very large gradients with many stops, or gradients animated on every frame, can cost rendering time. Static gradients on a few elements will not show up in your performance budget.
Conclusion
A web gradient background comes down to three decisions: which two colours you blend, where the stops sit, and whether text still reads against every part of the result. Get those right and the CSS is a single line.
Start with two nearby hues, write explicit stop positions, and test at three widths in both colour schemes. When you need to check a palette quickly, a free browser tool handles the sampling without an install. Keep your hex values in one place so the next palette change takes a minute, not an afternoon.