CSS Backgrounds with Multiple Gradient Layers: Foundations
TL;DR
- Multiple backgrounds = a comma‑separated stack. First image sits on top.
- Use any mix of
linear-gradient(),radial-gradient(),conic-gradient()(plus theirrepeating-variants), and of course - any image. background-colorpaints behind all images. Control paint boxes withbackground-clipandbackground-origin.- Learn the stack now; Part 2 dives into per‑layer control (
position/size/repeat/blend-mode).
Why this matters: layered CSS backgrounds let you ship rich visuals with no images, faster LCP, and crisp scaling on any DPI. Done right, it’s great for SEO and performance: fewer image downloads, smaller payloads, and easier iteration.
The mental model: a stack of layers
Backgrounds accept a comma‑separated list. The first item is the topmost layer, the last is the bottommost. background-color (if set) is below all layers.
background-image:
linear-gradient(to bottom, #f33 0%, #00f0 70%), /* layer 1 */
linear-gradient(to top left, #0f0 0%, #00f0 70%), /* layer 2 */
linear-gradient(to top right, #00f 0%, #00f0 70%); /* layer 3 */
Paint boxes and coordinates are controlled separately:
background-origin: which box positions the background (border/padding/content)background-clip: which box clips paint (border/padding/content/text)background-position/background-size: per‑layer placement and scale
Each of these can be provided as comma‑separated lists aligned with your layers (covered deeply in Part 2 CSS Background Layers: Position, Size, Repeat, Attachment, and Blend‑Mode).
Gradient types you can stack
linear-gradient(angle, stops...)radial-gradient(size at position, stops...)conic-gradient(from angle at position, stops...)repeating-linear-gradient(...),repeating-radial-gradient(...),repeating-conic-gradient(...)
You can freely combine them in a single background-image list.
A quick visual: 5‑layer hero
Preview box (pure CSS, no images):
background-color to maintain consistency.background-image:
radial-gradient(86% 76% at 84% 2.5%, #7C4DFF 0% 34%, transparent 100%),
radial-gradient(73% 88% at -4% 60%, #26C6DA 0% 33%, transparent 100%),
radial-gradient(86% 38% at 7.5% 79%, #00ACC1 0% 22%, transparent 100%),
radial-gradient(63% 39% at 31% 14%, #26C6DA 0% 22%, transparent 100%),
linear-gradient(101deg, #7C4DFF 0%, 61.8%, transparent 100%);
Painting areas: origin vs clip
The positioning and clipping boxes matter for precise effects like “inside‑padding only” textures or sharp borders.
/* Three layers: texture, highlight, base */
background-image:
radial-gradient(12px at 12px 12px, red, 50%, transparent 60%),
linear-gradient(180deg, #00ceaf9e, #00ceaf2e 40%),
linear-gradient(180deg, #ffffff60, #3d63ff6e);
background-originpicks the box used forposition/sizecoordinates.background-clipdefines where paint can appear (here we keep the upper layers away from the border).
/* Position inside content for top two, allow base to paint under border */
background-origin: content-box, content-box, border-box;
background-clip: content-box, content-box, border-box;
padding: 24px;
border: 8px solid var(--ui-border-accented);
border-radius: 8px;
Composition and stacking tips
- Start bottom‑up: lay a solid color or soft base gradient first.
- Add high‑level structure next (e.g., a large radial highlight).
- Spice with subtle texture or stripes at the top.
- Use blend modes sparingly; favor
soft-light,multiply, oroverlayfor tasteful depth.
Performance best practices
- Prefer CSS backgrounds when the effect is programmatic; reserve bitmaps for illustrative content.
- Reuse variables/tokens for colors to reduce cognitive load and keep brand consistency.
- Keep layers minimal (2–4) for most UI blocks. Measure FPS if animating.
Up next
- Part 2: precise control over each layer (
position/size/repeat/blend-mode) and how lists align. - (soon) Part 3: battle‑tested recipes (stripes, dots, grids, vignettes, glass, “mesh‑like” blends) with copy‑ready CSS.