Course contentsShow
← Web Development
Lesson 198 of 2,9823. CSS FundamentalsFree lesson

Multiple Backgrounds

Layer multiple background images with proper stacking order and individual property control.

Multiple Backgrounds

What you'll learn: How to layer multiple background images on a single element, each with its own positioning, size, and repeat behavior.

The Core Idea

Instead of limiting yourself to one background image per element, CSS allows you to stack multiple background images on top of each other. Think of it like a collage where you place several transparent sheets on top of one another—the first image you list appears on top, and each subsequent image sits behind it.

This layering system gives you creative flexibility: you might combine a texture overlay with a photograph, or add decorative elements to a solid color background without needing extra HTML elements.

How It Works

You simply separate each background property value with commas. The first value in the list appears closest to the user (on top), and the last value appears at the back.

.banner {
  background-image: 
    url('logo.png'),
    url('texture.png'),
    url('photo.jpg');
  
  background-position: 
    center top,
    left top,
    center center;
  
  background-size: 
    200px auto,
    100px 100px,
    cover;
  
  background-repeat: 
    no-repeat,
    repeat,
    no-repeat;
}

In this example, logo.png appears on top, texture.png in the middle, and photo.jpg as the backdrop. Each has its own positioning, sizing, and repeat rules.

You can also use the shorthand, separating each complete background layer with commas. Just remember: order matters—stacking is top to bottom in the order you write them.

Why Use Multiple Backgrounds?

Instead of adding extra <div> elements just to achieve layered visual effects, you can handle everything with CSS on a single element, keeping your HTML cleaner and more semantic.

Key Takeaway: Multiple backgrounds let you stack several images on one element by listing comma-separated values, with the first image appearing on top and each layer having independent control over position, size, and repeat behavior.