background

« CSS « CSS Reference

Summary

The background CSS property is a shorthand for setting the individual background values in a single place in the style sheet. background can be used to set the values for one or more of: background-color , background-image , background-position , background-repeat , background-size , and background-attachment .

The background shorthand property assigns explicit given values and sets missing properties to their initial values.

Syntax

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

where:

<bg-layer>
[ <background-image> || <background-repeat> || <background-attachment> || <background-position> ]
inherit
<final-bg-layer>
[ <background-color> || <background-image> || <background-repeat> || <background-attachment> || <background-position> ]
inherit
Note: The background-color can only be defined on the last background, as there is only one background color for the whole element.

Values

One or more of the following, in any order:

<background-color>
See background-color
<background-image>
See background-image
<background-repeat>
See background-repeat
<background-attachment>
See background-attachment
<background-position>
See background-position

Examples

View Live Examples

body { background: red; }

.topbanner { background: url("topbanner.png") #00D repeat-y fixed; }

Specifications

Specification Status Comment
CSS Backgrounds and Borders Module Level 3 Candidate Recommendation The shorthand property has been extended to support multiple backgrounds and the new background-size and background-clip properties.
CSS 2.1 Recommendation No significant changes
CSS 1 Recommendation  

Browser compatibility

  • Desktop
  • Mobile

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support 1.0 (1.7 or earlier) 1.0 4.0 3.5 1.0
Multiple backgrounds 3.6 (1.9.2) 1.0 9.0 [1] 10.5 1.3
SVG image as background 4.0 (2.0) (Yes) 9.0 # (Yes) (Yes)
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support 1.0 (1.9.2) 2.1 ? 10.0 3.2
Multiple backgrounds 1.0 (1.9.2) 2.1 ? 10.0 3.2
SVG image as background 4.0 (2.0) ? ? ? ?

Tags (2)

Edit tags

Attachments (0)

 

Attach file