Gradient Background

Build a smooth gradient background and copy the CSS.

Steps to make a gradient background

  1. Add two or more color stops, then drag them to set where each color sits.
  2. Set the angle so the blend runs the way you want, like 180deg for top to bottom.
  3. Copy the background rule, and add min-height: 100vh so it fills the screen.
  4. Drop a stop into the Color Picker if you need to fine-tune a shade.

What is a gradient background?

A gradient background is a smooth blend of colors set as an element’s background instead of a flat fill or a downloaded image. Because the browser paints it, there is no file to load, it stays razor sharp at any size, and it scales to any screen. It is the quickest way to add depth behind a page, a hero section, a card or a button.

Why a gradient background does not cover the full page

This is the single most searched gradient-background problem, and it is almost never the gradient’s fault. A background only stretches as far as its element, so a short page leaves the color stopping partway down with a blank strip below. The usual fixes:

SymptomCauseFix
Stops partway downBody shorter than the screenAdd min-height: 100vh to the body
Thin white border at edgesDefault browser marginsSet margin: 0 on html and body
Color tiles or repeatsBackground repeats by defaultAdd background-repeat: no-repeat
Ends when you scrollBackground sized to the viewportUse background-attachment: fixed
A reliable full-page base: body { margin: 0; min-height: 100vh; background: linear-gradient(180deg, #4F46E5, #06B6D4) no-repeat; }

How to layer a gradient over an image

A dark gradient over a photo is how readable hero text gets its contrast, but the order trips people up. In a layered background the first layer is drawn on top, so the gradient must come before the url(), not after:

background: linear-gradient(rgba(0,0,0,.5), rgba(0,0,0,.5)), url("hero.jpg"); background-size: cover; darkens the photo so white text stays legible.

How to make a mesh gradient background

Mesh and aurora backgrounds are not a special property; they are several radial gradients stacked in one declaration, each with its own position and a fade to transparent. Two rules keep them clean:

  • Separate each radial-gradient with a comma in a single background value.
  • Fade with rgba(…, 0), not the bare transparent keyword, to avoid a gray haze.
  • Give each blob a different at position so they spread across the box.
  • Keep the colors close in lightness for a soft, modern blend.
  • Build and copy the stack quickly with the Gradient Generator.

Where gradient backgrounds get used

  • Full-page and hero backdrops that load instantly with no image.
  • Cards and panels that need a hint of depth.
  • Dark overlays on photos to keep heading text readable.
  • Animated backgrounds, shifting the stops with CSS keyframes.

Gradient background vs background image

CSS gradientImage file
File weightZero, drawn by browserKilobytes to megabytes
SharpnessCrisp at any sizeCan blur when scaled
EditingChange a value in CSSRe-export the file
Best forColor blends, overlaysPhotos, detailed art
Why does my gradient background not fill the whole page?

The body is shorter than the screen, so the background stops with it. Add min-height: 100vh and margin: 0 to the body.

How do I stop a gradient background from repeating?

Add background-repeat: no-repeat. A background tiles by default, which can show seams on large screens.

How do I keep the gradient fixed while the page scrolls?

Add background-attachment: fixed so it pins to the viewport. Note that fixed attachment is unreliable on some mobile browsers.

Why is my gradient invisible on an empty div?

A background needs the element to have size. Give the div a height or padding, or content, so there is an area to paint.

How do I darken a photo with a gradient?

List the gradient before the url() in one background value, since the first layer is drawn on top, then add background-size: cover.

You might also like