O'Reilly logo

CSS Pocket Reference, 4th Edition by Eric A. Meyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

background

Values:

[ <bg-layer> , ]* <final-bg-layer>

Expansions:

<bg-layer>

<bg-image> || <bg-position> [ / <bg-size> ]? || <bg-repeat> || <bg-attachment'> || < bg-box>{1,2}

<final-bg-layer>

<bg-image> || <bg-position> [ / <bg-size> ]? || <bg-repeat> || <bg-attachment'> || < bg-box>{1,2} || <bg-color>

Initial value:

Refer to individual properties

Applies to:

All elements

Inherited:

No

Percentages:

Allowed for <bg-position> (see background-position) and refer to both the dimensions of the element’s background area and the dimensions of the origin image

Computed value:

See individual properties

Description:

A shorthand way of expressing the various background properties of one or more element backgrounds using a single declaration. As with all shorthands, this property will set all of the allowed values (e.g., the repeat, position, and so on) to their defaults if the values are not explicitly supplied. Thus, the following two rules will have the same appearance:

  background: yellow;
  background: yellow none top left repeat;

Furthermore, these defaults can override previous declarations made with more specific background properties. For example, given the following rules:

  h1 {background-repeat: repeat-x;}
  h1, h2 {background: yellow url(headback.gif);}

…the repeat value for both h1 and h2 elements will be set to the default of repeat, overriding the previously declared value of repeat-x.

When declaring multiple backgrounds, only the last may have a background color. In cases where multiple background ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required