Backgrounds, Borders, and Visual Layers
Compose resilient surfaces with layered backgrounds, images, borders, radii, and contrast-aware decoration.
Backgrounds paint behind an element's content and border without changing document structure. Multiple background layers are listed from front to back, and each layer can set its own image, position, size, and repetition. A fallback background color still matters when an image is unavailable or transparent.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.hero { background-color: #17324d; background-image: linear-gradient(90deg, rgb(23 50 77 / .88), rgb(23 50 77 / .35)), url('/images/home/learning-paths.jpg'); background-size: cover; background-position: center; color: white; border: 2px solid rgb(255 255 255 / .35); border-radius: 1rem; }Working rules
- Keep text readable when a background image fails
- Use border radius consistently with overflow and focus states
- Treat decorative images as decoration, not essential content
A common mistake
A background image has no alternative-text mechanism, so it must not be the only carrier of essential information.
Guided practice
Build a readable hero that still communicates its message when the image request fails.
- Copy the example into the editable notebook below.