background-image CSS property

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

The background-image CSS property sets one or more background images on an element.

Try it

background-image: url("../../../../../../shared-assets/images/examples/lizard.png");
background-image:
  url("../../../../../../shared-assets/images/examples/lizard.png"),
  url("../../../../../../shared-assets/images/examples/star.png");
background-image:
  url("../../../../../../shared-assets/images/examples/star.png"),
  url("../../../../../../shared-assets/images/examples/lizard.png");
background-image:
  linear-gradient(rgb(0 0 255 / 0.5), rgb(255 255 0 / 0.5)),
  url("../../../../../../shared-assets/images/examples/lizard.png");
<section id="default-example">
  <div id="example-element"></div>
</section>
#example-element {
  min-width: 100%;
  min-height: 100%;
  padding: 10%;
}

Syntax

css
/* single image */
background-image: linear-gradient(black, white);
background-image: url("cat-front.png");

/* multiple images */
background-image:
  radial-gradient(circle, transparent 45%, black 48%),
  radial-gradient(ellipse farthest-corner, #fc1c14 20%, #cf15cf 80%);

/* Global values */
background-image: inherit;
background-image: initial;
background-image: revert;
background-image: revert-layer;
background-image: unset;

Each background image is specified either as the keyword none or as an <image> value.

To specify multiple background images, supply multiple values, separated by a comma.

Values

none

Is a keyword denoting the absence of images.

<image>

Is an <image> denoting the image to display. There can be several of them, separated by commas, as multiple backgrounds are supported.

Description

The background images are drawn on stacking context layers on top of each other. The first layer specified is drawn as if it is closest to the user.

The borders of the element are then drawn on top of them, and the background-color is drawn beneath them. How the images are drawn relative to the box and its borders is defined by the background-clip and background-origin CSS properties.

If a specified image cannot be drawn (for example, when the file denoted by the specified URI cannot be loaded), browsers handle it as they would a none value.

Note: Even if the images are opaque and the color won't be displayed in normal circumstances, web developers should always specify a background-color. If the images cannot be loaded—for instance, when the network is down—the background color will be used as a fallback.

Accessibility

Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.

Additionally, it is important to ensure that the contrast ratio between the background image and the foreground text is high enough that people with low vision can read the page content.

Color contrast ratio is determined by comparing the luminance of the text and background color values. To meet Web Content Accessibility Guidelines (WCAG), a ratio of 4.5:1 is required for body text content and 3:1 for larger text such as headings. Large text is defined as 24px or larger, or bolded 18.66px or larger.

Formal definition

Initial valuenone
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valueas specified, but with <url> values made absolute
Animation typediscrete

Formal syntax

background-image = 
<bg-image>#

<bg-image> =
<image> |
none

<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>

<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )

<image-set()> =
image-set( <image-set-option># )

<cross-fade()> =
cross-fade( <cf-image># )

<element()> =
element( <id-selector> )

<image-tags> =
ltr |
rtl

<image-src> =
<url> |
<string>

<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?

<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?

<id-selector> =
<hash-token>

Examples

Layering background images

Note that the star image is partially transparent and is layered over the cat image.

HTML

html
<div>
  <p class="cats-and-stars">This paragraph is full of cats<br />and stars.</p>
  <p>This paragraph is not.</p>
  <p class="cats-and-stars">Here are more cats for you.<br />Look at them!</p>
  <p>And no more.</p>
</div>

CSS

css
p {
  font-weight: bold;
  font-size: 1.5em;
  color: white;
  text-shadow: 0.07em 0.07em 0.05em black;
  background-image: none;
  background-color: transparent;
}

div {
  background-image: url("mdn_logo_only_color.png");
}

.cats-and-stars {
  background-image: url("star-transparent.gif"), url("cat-front.png");
  background-color: transparent;
}

Result

Specifications

Specification
CSS Backgrounds and Borders Module Level 3
# background-image

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
background-image
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote
footnote If the browser.display.use_document_colors user preference in about:config is set to false, background images will not be displayed.
Opera – Full support
Opera 3.5 (Release date: 1998-11-18)
footnote Full support
Safari – Full support
Safari 1 (Release date: 2003-06-23)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote
footnote If the browser.display.use_document_colors user preference in about:config is set to false, background images will not be displayed.
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
element()
Experimental
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
prefix
prefix Implemented with the vendor prefix: -moz-
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
prefix
prefix Implemented with the vendor prefix: -moz-
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
Gradients
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 3.6 (Release date: 2010-01-21)
footnote
footnote Some versions support only experimental gradients prefixed with -moz.
Opera – Full support
Opera 11 (Release date: 2010-12-16)
footnote
footnote Some versions support only experimental gradients prefixed with -o.
Safari – Full support
Safari 4 (Release date: 2009-06-08)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote
footnote Some versions support only experimental gradients prefixed with -moz.
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
Safari on iOS – Full support
Safari on iOS 3.2 (Release date: 2010-04-03)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
WebView on iOS – Full support
WebView on iOS 3.2 (Release date: 2010-04-03)
footnote
footnote Some versions support only experimental gradients prefixed with -webkit.
image-rect()
Deprecated Non-standard
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox 4 – 119 (Release date: 2011-03-22)
prefix
footnote Removed in 120 and later
prefix Implemented with the vendor prefix: -moz-
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android 4 – 119 (Release date: 2011-03-29)
prefix
footnote Removed in 120 and later
prefix Implemented with the vendor prefix: -moz-
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
image-set()
Chrome – Partial support
Chrome 20 – 112 (Release date: 2012-06-26)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Chrome – Full support
Chrome 113 (Release date: 2023-05-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome – Full support
Chrome 113 (Release date: 2023-05-02)
footnote Full support
Edge – Partial support
Edge 79 – 112 (Release date: 2020-01-15)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Edge – Full support
Edge 113 (Release date: 2023-05-05)
prefix
prefix Implemented with the vendor prefix: -webkit-
Edge – Full support
Edge 113 (Release date: 2023-05-05)
footnote Full support
Firefox – Partial support
Firefox 88 – 88 (Release date: 2021-04-19)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Firefox – Full support
Firefox 90 (Release date: 2021-07-13)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox – Full support
Firefox 89 (Release date: 2021-06-01)
footnote Full support
Opera – Partial support
Opera 15 – 98 (Release date: 2013-07-02)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Opera – Full support
Opera 99 (Release date: 2023-05-16)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera – Full support
Opera 99 (Release date: 2023-05-16)
footnote Full support
Safari – Partial support
Safari 6 – 13.1 (Release date: 2012-07-25)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Safari – Partial support
Safari 10.1 – 13.1 (Release date: 2017-03-27)
footnote Partial support
footnote Support for url images only and x is the only supported resolution unit.
Safari – Partial support
Safari 14 – 16.6 (Release date: 2020-09-16)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote The type() function is not supported as an argument to image-set().
Safari – Partial support
Safari 14 – 16.6 (Release date: 2020-09-16)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Safari – Full support
Safari 17 (Release date: 2023-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari – Full support
Safari 17 (Release date: 2023-09-18)
footnote Full support
Chrome Android – Partial support
Chrome Android 25 – 112 (Release date: 2013-02-27)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Chrome Android – Full support
Chrome Android 113 (Release date: 2023-05-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome Android – Full support
Chrome Android 113 (Release date: 2023-05-02)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 88 – 88 (Release date: 2021-04-19)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Firefox for Android – Full support
Firefox for Android 90 (Release date: 2021-07-13)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox for Android – Full support
Firefox for Android 89 (Release date: 2021-06-01)
footnote Full support
Opera Android – Partial support
Opera Android 14 – 75 (Release date: 2013-05-21)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Opera Android – Full support
Opera Android 76 (Release date: 2023-06-26)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera Android – Full support
Opera Android 76 (Release date: 2023-06-26)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 6 – 13.4 (Release date: 2012-09-10)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Safari on iOS – Partial support
Safari on iOS 10.3 – 13.4 (Release date: 2017-03-27)
footnote Partial support
footnote Support for url images only and x is the only supported resolution unit.
Safari on iOS – Partial support
Safari on iOS 14 – 16.6 (Release date: 2020-09-16)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote The type() function is not supported as an argument to image-set().
Safari on iOS – Partial support
Safari on iOS 14 – 16.6 (Release date: 2020-09-16)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 1.5 – 22 (Release date: 2013-09-25)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Samsung Internet – Full support
Samsung Internet 23 (Release date: 2023-10-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Samsung Internet – Full support
Samsung Internet 23 (Release date: 2023-10-18)
footnote Full support
WebView Android – Partial support
WebView Android 4.4 – 112 (Release date: 2013-12-09)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
WebView Android – Full support
WebView Android 113 (Release date: 2023-05-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView Android – Full support
WebView Android 113 (Release date: 2023-05-02)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 6 – 13.4 (Release date: 2012-09-10)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
WebView on iOS – Partial support
WebView on iOS 10.3 – 13.4 (Release date: 2017-03-27)
footnote Partial support
footnote Support for url images only and x is the only supported resolution unit.
WebView on iOS – Partial support
WebView on iOS 14 – 16.6 (Release date: 2020-09-16)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote The type() function is not supported as an argument to image-set().
WebView on iOS – Partial support
WebView on iOS 14 – 16.6 (Release date: 2020-09-16)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
footnote Full support
Multiple backgrounds
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 3.6 (Release date: 2010-01-21)
footnote Full support
Opera – Full support
Opera 10.5 (Release date: 2010-03-02)
footnote Full support
Safari – Full support
Safari 1.3 (Release date: 2005-04-15)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
none
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 1 (Release date: 2003-06-23)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
SVG images
Chrome – Full support
Chrome 8 (Release date: 2010-12-02)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
footnote Full support
Opera – Full support
Opera 9.5 (Release date: 2008-06-12)
footnote Full support
Safari – Full support
Safari 5 (Release date: 2010-06-07)
footnote
footnote Support of SVG in CSS background is incomplete.
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 5 (Release date: 2011-10-12)
footnote
footnote Support of SVG in CSS background is incomplete.
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 5 (Release date: 2011-10-12)
footnote
footnote Support of SVG in CSS background is incomplete.

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also