css properties background

The background shorthand CSS property sets all background style properties at once, such as color, image, origin and size, or repeat method. Component properties not set in the background shorthand property value declaration are set to their default values.

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

/* Using a <background-color> */
background: green;

/* Using a <bg-image> and <repeat-style> */
background: url("test.jpg") repeat-y;

/* Using a <box> and <background-color> */
background: border-box red;

/* A single image, centered and scaled */
background: no-repeat center/80% url("../img/image.png");

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

The background property is specified as one or more background layers, separated by commas.

The syntax of each layer is as follows:

Values

<attachment>

See background-attachment. Default: scroll.

<box>

See background-clip and background-origin. Default: border-box and padding-box respectively.

<background-color>

See background-color. Default: transparent.

<bg-image>

See background-image. Default: none.

<position>

See background-position. Default: 0% 0%.

<repeat-style>

See background-repeat. Default: repeat.

<bg-size>

See background-size. Default: auto.

The following three lines of CSS are equivalent:

background: none;
background: transparent;
background: repeat scroll 0% 0% / auto padding-box border-box none transparent;

Accessibility concerns

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.

Examples

Setting backgrounds with color keywords and images

HTML

<p class="topbanner">
  Starry sky<br />
  Twinkle twinkle<br />
  Starry sky
</p>
<p class="warning">Here is a paragraph</p>
<p></p>

CSS

.warning {
  background: pink;
}

.topbanner {
  background: url("starsolid.gif") #99f repeat-y fixed;
}

See also