CSS background-image Property

Beginner
7 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The background-image property paints one or more images behind an element's content. Each image is a file, written with url(), or a generated image such as linear-gradient() or radial-gradient(). List several images with commas. The first image is painted on top, closest to the reader.

background-color is painted underneath those images. The initial value is none. The property is not inherited, and it applies to every element, including ::first-letter and ::first-line. background-clip and background-origin decide which box the image fills.

Standard.

Not deprecated. url(), gradients, and multiple layers are Baseline. element(), the image() type, and paint() are experimental and missing in most browsers.

CSS Syntax

syntax.css
background-image: none | url() | linear-gradient() | radial-gradient() | conic-gradient() | initial | inherit;

Separate multiple images with commas. repeating-linear-gradient() is a gradient that tiles its own fade.

Property Values

ValueDescriptionTry it
noneNo image. This is the initial valueTry it
url()An image file. The path is relative to the style sheetTry it
linear-gradient()A straight color fade. The gradient is an imageTry it
radial-gradient()A circular or elliptical fade from a center pointTry it
conic-gradient()A sweep around a center, like a color wheelTry it
repeating-linear-gradient()The same straight fade, repeated into stripesTry it
image, imageA comma-separated list. The first image is on topTry it
initialResets this property to noneTry it
inheritCopies this property from the parent elementTry it

How to Use background-image

Choose the element, give the image a box to paint in, then set one image or a stack.

  1. Set background-image on the element that should show the picture. It is not inherited.
  2. Give that element a size. An empty box with no height has no visible image. Content or height is enough.
  3. Use none, one url() or gradient, or a comma-separated list. The first listed image is on top.
  4. Set a background-color as well. It shows when a file fails to load, and it sits under every layer.
PieceRequired?Role
ElementYesThe box that receives the image
A visible areaYesContent or a height, so the image has somewhere to paint
background-imageYesnone, one image, or a comma-separated list
background-colorRecommendedThe color under the images, and the fallback if a file fails
background-repeat, background-size, background-positionNoHow a chosen image tiles, scales, and sits. They do not choose the image

Live Preview

One box. Change background-image and watch the paint behind the label.

The label stays in the content. Only the paint behind it changes.

Image
Blue to purple

background-image: linear-gradient(#2563eb, #7c3aed)

CSS Examples

Each snippet adds only what background-image needs: a box with a size, and the image. Use Try It Yourself for a live editor.

Example 1 — Linear Gradient

Paint a straight fade from blue to purple behind the words.

CSS
<style>
  div {
    height: 140px;
    padding: 16px;
    color: #fff;
    background-image: linear-gradient(#2563eb, #7c3aed);
  }
</style>

<div>Blue to purple</div>
Try It Yourself

How It Works

  1. Give the image a box. height: 140px makes an empty-looking area tall enough to see the fade. padding insets the words.
  2. Build an image, not a color. linear-gradient(#2563eb, #7c3aed) fades from the first color to the second, top to bottom.
  3. Paint it behind the text. background-image draws that fade in the box. The words stay in normal flow on top of it.
  4. Keep the words readable. color: #fff is text color. It is there so the label meets contrast on the dark fade. It does not create the gradient.

Example 2 — Image File

Tile a small drawing with url(). A color sits underneath the dots.

CSS
<style>
  div {
    height: 140px;
    padding: 16px;
    color: #1e3a8a;
    background-color: #eff6ff;
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28'><circle cx='8' cy='8' r='3' fill='%232563eb'/><circle cx='22' cy='22' r='3' fill='%237c3aed'/></svg>");
  }
</style>

<div>Tiled file</div>
Try It Yourself

How It Works

  1. Point at a file. url() loads an image. This one is a tiny SVG stored in the value, so the example needs no extra file. %23 is the encoded # in each dot color.
  2. Quote the address. The double quotes keep the path one value. A normal project path such as url("images/dot.svg") is resolved from the style sheet, not from the HTML file.
  3. Put a color under it. background-color: #eff6ff fills the gaps and remains if the file cannot load.
  4. The dots repeat. A small image tiles because background-repeat starts at repeat. That tiling is the other property's initial value.

Example 3 — Two Layers

Lay a dark tint over a second fade. The first gradient in the list is on top.

CSS
<style>
  div {
    height: 140px;
    padding: 16px;
    color: #fff;
    background-image:
      linear-gradient(rgba(15, 23, 42, 0.55), rgba(15, 23, 42, 0.55)),
      linear-gradient(135deg, #0ea5e9, #6366f1);
  }
</style>

<div>Tint on top</div>
Try It Yourself

How It Works

  1. Write two images. A comma splits the list into two layers. Both are gradients, so no file is requested.
  2. The first layer is on top. rgba(15, 23, 42, 0.55) is a translucent dark tint. You still see the fade behind it.
  3. The second layer is behind. linear-gradient(135deg, #0ea5e9, #6366f1) runs from sky blue to indigo on a diagonal.
  4. The color would be last. A background-color would sit under both images. This pair is already opaque, so the tint and the fade are what you see.

Edge Cases & Pitfalls

If the picture is missing, unreadable, or in the wrong order, one of these is usually why.

a11y

Screen readers skip it

Assistive technology is not told about a background image. Information belongs in an img with alt. Use this property for decoration, and keep the text contrast at 4.5:1 against the paint.

color

A failed file is treated as none

If the address 404s, that layer disappears. Set a background-color so something remains. An opaque gradient covers that color; the color is still underneath.

order

The first image is the top image

In url("photo.webp"), linear-gradient(...) the file is on top and the gradient is the backup behind it. Reversing the list hides the file under an opaque gradient.

reset

The background shorthand clears the image

A later background: #fff sets every background longhand, including background-image: none. Set the image after the shorthand, or include the image in the shorthand.

path

url() starts from the style sheet

A path is resolved from the CSS file, not from the HTML page. url("images/dot.svg") in /css/site.css requests /css/images/dot.svg.

Browser Support

background-image is a browser painting property. Node.js, Deno, and Bun do not apply it. url() and none are older than gradients. conic-gradient() is newer. element(), the image() type, and paint() are experimental.

✓ Baseline · Widely available since 2015

background-image

url() and none: every current browser. Multiple layers: Internet Explorer 9+. linear-gradient and radial-gradient: Chrome 26+, Firefox 16+, Safari 7+, Edge 12+. conic-gradient: Chrome 69+, Firefox 83+, Safari 12.1+.

99% url() and gradients
Google Chrome 1+ url · 26+ gradients · 69+ conic
Full support
Mozilla Firefox 1+ url · 16+ gradients · 83+ conic
Full support
Apple Safari 1+ url · 7+ gradients · 12.1+ conic
Full support
Microsoft Edge 12+ gradients · 79+ conic
Full support
Opera 3.5+ url · 12.1+ gradients
Full support
Samsung Internet 4+ gradients · 10+ conic
Full support
Internet Explorer 4+ url · 9+ layers · 10+ gradients
Partial
background-image Widely supported

Bottom line: Safe for url(), multiple layers, linear-gradient(), and radial-gradient() in current browsers. conic-gradient() needs Chrome 69, Firefox 83, or Safari 12.1, and is absent in Internet Explorer. element(), the image() type, and paint() are experimental — skip them on a normal page.

Key Takeaways

  • Role: paint one image, or a stack of images, behind the content. Files use url(). Gradients are images too.
  • Order: the first image in a comma list is on top. background-color is behind all of them.
  • Initial value: none. It is not inherited. initial clears the image. inherit copies the parent.
  • Meaning: screen readers ignore it. Put information in an img with alt. Keep a fallback color.

One line: background-image chooses the picture. Repeat, size, and position only change how that picture sits in the box.

Frequently Asked Questions

It paints one or more images behind an element's content. The image can be a file, a gradient, or a comma-separated stack. The text stays on top. The initial value is none, and the property is not inherited.
none. The element has no background image until you set one. A background-color can still show, because the color is a different property and is painted underneath.
Yes. linear-gradient(), radial-gradient(), and conic-gradient() produce images. An opaque gradient covers the background-color. A transition swaps one image for another; it does not cross-fade, because the animation type is discrete.
The first image in the list is painted closest to the reader. The next image sits behind it. The background-color sits behind every image.
Browsers do not expose background images to assistive technology. If the picture carries information, use an img element with alt text. Keep background-image for decoration, and keep text contrast strong against the picture.
url() and none work in every current browser and in old Internet Explorer. Multiple layers need Internet Explorer 9 or newer. Standard linear-gradient and radial-gradient need Chrome 26, Firefox 16, Safari 7, or Edge 12. conic-gradient needs Chrome 69, Firefox 83, or Safari 12.1. This is a browser CSS property. Node.js, Deno, and Bun do not paint it.

Next: background-origin

Learn which box the image is positioned against: border, padding, or content.

background-origin tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful