Backgrounds, Gradients & Multi-Layers
Every element in CSS is a canvas that can stack multiple layers: transparent dot matrices, rich linear & conic gradients, and responsive background images with pure CSS fixed parallax scrolling.
1. The Mental Model: Stack of Transparent Glass Sheets
In CSS, background-image accepts a comma-separated list of values. Think of each item as a transparent glass sheet stacked on top of your desk:
Pattern overlay or semi-transparent noise dots. Anything transparent here reveals the sheet underneath.
Gradient or hero illustration. First declared layer renders on top of later declared layers!
background-color is always the fallback bottom surface beneath all image layers.
2. The 3 Gradient Types in Modern CSS
Linear Gradient
Transitions colors along a straight ray defined by an angle (e.g. 90deg) or directional keywords (to bottom right).
linear-gradient(45deg, #ec4899, #8b5cf6)
Radial Gradient
Radiates outward from a central anchor point in concentric circles or ellipses. Perfect for spot lights, badges, and glow orbs.
radial-gradient(circle at center, #8b5cf6, #1e1b4b)
Conic Gradient
Rotates colors around a center pin like a radar sweep or color wheel. Build pure CSS pie charts and circular progress bars!
conic-gradient(from 0deg, #ec4899, #3b82f6)
3. Interactive Studio: Gradient Mixer & Multi-Layer Engine
Pure CSS Hero Card
Zero external image files required. Pure mathematical GPU rasterization renders instantaneously on any screen resolution.
Pure CSS Parallax in 1 Line
Add background-attachment: fixed; to make an image stick to the browser viewport while the rest of the document scrolls past it. No JavaScript event listeners or scroll lagging!
First-Year Student Traps: Backgrounds
- 1.The Background Shorthand Slash Syntax: In the shorthand
backgroundproperty, you must separate position and size with a slash:background: url('bg.jpg') center / cover no-repeat;. Leaving out the slash makes the browser drop the size entirely! - 2.Mobile iOS Fixed Background Bug:
background-attachment: fixedoften malfunctions or triggers heavy repaint stutters in Safari on iOS devices. The modern workaround is a fixed pseudo-element withposition: fixed; inset: 0; z-index: -1;. - 3.The Missing Fallback Color: Never declare a dark text hero over a dark image without adding a matching
background-color: #0f172afallback. If the client has a 3G network or ad-blocker blocking images, the user will see black text on white default background!
Borders, Outlines & Geometric Shapes
Master 8-value border-radius blobs, outline offsets for accessibility, and border-image ribbons.