background-color
The safest base layer for a surface.
Backgrounds create surfaces, depth and visual context. They can be simple colors, images, gradients or layered effects.
.hero {
background: linear-gradient(rgba(7,17,31,.8), rgba(7,17,31,.8)), #07111f;
}
Typography & Visual Style
The background property can control color, images, gradients, repeat behavior, position and size.
A background is often part of the reading environment. If it is too busy, low contrast or poorly cropped, the content suffers.
Professional CSS treats backgrounds as layers: base color, surface treatment, image, overlay and foreground readability.
The safest base layer for a surface.
Can use images, gradients or multiple layers.
cover fills the box; contain keeps the full image visible.
Controls which part of an image remains visible.
Visual model
Typography and visual style are where CSS starts to feel like design. These models turn subjective choices into reusable decisions you can explain, test and improve.
Examples
.hero {
background:
linear-gradient(rgba(7, 17, 31, .76), rgba(7, 17, 31, .76)),
url("/assets/images/lesson.jpg") center / cover;
}
.hero {
background-image: url("/assets/images/busy-photo.jpg");
color: white;
}
Rules that matter
A beautiful one-off style is not enough. The goal is a visual system that keeps working when the site grows, content changes and new pages are added.
A background color protects the design while images load or fail.
Use overlays when text sits on images.
cover crops; contain may leave empty space.
background-position decides what stays visible.
A busy background can make even good typography fail.
Images crop differently on mobile and desktop.
Production thinking
Backgrounds establish atmosphere and surface hierarchy, but content must remain the boss.
Text over images needs strong contrast. Do not rely on a background image to communicate essential information.
Optimize background images and define fallback colors. Large decorative images can slow the page.
Important images should usually be real img elements with alt text, not only CSS backgrounds.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If your answer is vague, change the lab values and judge the visual result again.
Senior audit upgrade
Large background images can be heavy, and text over imagery needs a real contrast strategy.
Compress and size backgrounds for the largest real display need, not the original camera file.
Use overlays or surface layers when text sits on complex imagery.
Set a readable background color for slow image loading.