CSS Backgrounds
The background is a layered canvas: color at the bottom, then any number of images — including gradients — stacked with their own size, position and repeat. Learn the layers and half of "CSS magic" demystifies itself.
1. The background properties
header {
background-color: #20242A; /* bottom layer */
background-image: url("hero.jpg");
background-size: cover; /* fill, crop edges */
background-position: center;
background-repeat: no-repeat;
}cover scales the image to fill the box (cropping overflow); contain fits it entirely inside (possibly letterboxing). background-attachment: fixed pins the image while content scrolls — this very site's gradient canvas uses it.
2. Layering: commas stack backgrounds
hero {
background:
linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.45)),
url("team.jpg") center / cover no-repeat;
}The first layer paints on top. A translucent gradient over a photo is the standard recipe for readable hero text. Gradients count as images — which is why the whole Gradient generator family lives in this property.
3. Try it yourself
Make the hero readable: add a dark translucent gradient layer above the existing gradient "photo" (stack them with a comma) — try linear-gradient(rgba(0,0,0,.5), rgba(0,0,0,.5)) as the first layer.
4. Quiz — check your understanding
CSS Backgrounds Quiz
4 questions · pass at 60%Q1. background-size: cover will…
Q2. How do you stack multiple backgrounds on one element?
Q3. In a stacked background, which layer paints on top?
Q4. A CSS gradient is technically a…
Every lesson quiz you pass (60%+) is saved in your browser and counts toward the CSSmatic Certificate of Completion.