Skip to main content

CSS Multiple Backgrounds

CSS lets you add more than one background image to an element using the background-image property.

Separate each image with a comma. The images stack on top of each other, with the first image closest to the viewer.

Individual background properties

This example uses two background images with individual properties: background-image, background-position, and background-repeat. The first image is a flower aligned to the right bottom, and the second is a paper texture that repeats.

Prompt
Create a page with a div that has two background images using individual CSS background properties: background-image, background-position, and background-repeat. The first image (a small flower, use "img_flwr.gif") should be aligned to the right bottom with no-repeat, and the second image (a paper texture, use "paper.gif") should repeat from the top-left. Add some lorem ipsum text inside the div.
Output: complete HTML page

Background shorthand property

You can also use the background shorthand property to set multiple backgrounds in one declaration. This gives the same result as the example above.

Prompt
Create a page with a div that has two background images using the CSS background shorthand property. The first image ("img_flwr.gif") should be right bottom no-repeat, and the second image ("paper.gif") should be left top repeat. Add some lorem ipsum text inside the div.
Output: complete HTML page

CSS Advanced Background Properties

Here are the CSS background properties used for advanced backgrounds:

  • background — a shorthand property for setting all background properties in one declaration.
  • background-clip — sets the painting area of the background.
  • background-image — sets one or more background images for an element.
  • background-origin — sets where the background image is positioned.
  • background-size — sets the size of the background image.