CSS3 module: Backgrounds

W3C Working Draft 24 September 2001

This version:
Latest version:
Previous versions:
Tim Boland (NIST)
Bert Bos (W3C)


CSS (Cascading Style Sheets) is a language for describing the rendering of HTML and XML documents on screen, on paper, in speech, etc. This draft describes the functionality that is proposed for CSS level 3 to describe backgrounds, such as background colors and background images. It includes and extends the functionality of CSS level 2 [CSS2], which builds on CSS Level 1 [CSS1].

Status of this document

This document is a draft of one of the "modules" [CSS3-intro] for the upcoming CSS3 specification. It not only describes the background functionality that already exists in CSS1 and CSS2, but also proposes new functionality for CSS3 as well as for other languages that may need it. (This draft does not yet propose any new functionality, but future versions will.)

This document is a working draft of the CSS working group which is part of the style activity.

Comments on, and discussions of this draft can be sent on the (archived) public mailing list www-style@w3.org (see instructions). W3C Members can also send comments directly to the CSS working group.

This is a working draft and may therefore be updated, replaced or rendered obsolete by other W3C documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". Its publication does not imply endorsement by the W3C membership or the CSS Working Group (members only).

To find the latest version of this working draft, please follow the "Latest version" link above, or visit the list of W3C Technical Reports.

This document may be available in translations in the future. The English version of this specification is the only normative version.

Table of contents

1. Dependencies with other CSS 3 Modules

2. Context

Members of the CSS Working Group proposed during the Clamart meeting to modularize the CSS specification.

This modularization, and the externalization of the general syntax, of CSS will reduce the size of the specification and allow new types of specifications to use selectors and/or CSS general syntax.

This specification will contain its own test cases, one test per concept introduced in this document. These tests will not be conformance full tests but will be intended to provide users with a way to check if a part of this specification is implemented at least a minima or not or, on the contrary, not implemented at all.

2.1. Changes from CSS 2

Editor's Note: A new property ('background-size') will be added to this specification in the near future.

'Background-clip' and 'background-origin' are new.

3. Background

Authors may specify the background of an element (i.e., its rendering surface) as either a color or an image. In terms of the box model [CSS3-box], "background" refers to the background of the content, padding and border areas. Margins are always transparent so the background of the parent box always shines through.

Background properties are not inherited, but the parent box's background will shine through by default because of the initial 'transparent' value on 'background-color'.

The background of the box generated by the root element covers the entire canvas.

For HTML documents, however, we recommend that authors specify the background for the BODY element rather than the HTML element. User agents should observe the following precedence rules to fill in the background: if the value of the 'background' property for the HTML element is different from 'transparent' then use it, else use the value of the 'background' property for the BODY element. If the resulting value is 'transparent', the rendering is undefined.

According to these rules, the canvas underlying the following HTML document will have a "marble" background:

    <TITLE>Setting the canvas background</TITLE>
    <STYLE type="text/css">
       BODY { background: url("http://style.com/marble.png") }
    <P>My background is marble.

3.1. The 'background-color' property

Name: background-color
Value: <color> | transparent | inherit
Initial: transparent
Applies to: all elements
Inherited: no
Percentages: N/A
Media: visual

This property sets the background color of an element, either a <color> value or the keyword 'transparent', to make the underlying colors shine through.


H1 { background-color: #F00 }

3.2. The 'background-image property

Name: background-image
Value: <uri> | none | inherit
Initial: none
Applies to: all elements
Inherited: no
Percentages: N/A
Media: visual

This property sets the background image of an element. When setting a background image, authors should also specify a background color that will be used when the image is unavailable. When the image is available, it is rendered on top of the background color. (Thus, the color is visible in the transparent parts of the image).

Values for this property are either <uri>, to specify the image, or 'none', when no image is used.


BODY { background-image: url("marble.gif") }
P { background-image: none }

3.3. The 'background-repeat' property

Name: background-repeat
Value: repeat | repeat-x | repeat-y | no-repeat | inherit
Initial: repeat
Applies to: all elements
Inherited: no
Percentages: N/A
Media: visual

If a background image is specified, this property specifies whether the image is repeated (tiled), and how. All tiling covers the content, padding and border areas of a box. Values have the following meanings:

The image is repeated both horizontally and vertically.
The image is repeated horizontally only.
The image is repeated vertically only.
The image is not repeated: only one copy of the image is drawn.


  background: white url("pendant.gif");
  background-repeat: repeat-y;
  background-position: center;

A centered background image, with copies repeated up and down
the border, padding and content areas.

One copy of the background image is centered, and other copies are put above and below it to make a vertical band behind the element.

3.4. The 'background-attachment' property

Name: background-attachment
Value: scroll | fixed | inherit
Initial: scroll
Applies to: all elements
Inherited: no
Percentages: N/A
Media: visual

If a background image is specified, this property specifies whether it is fixed with regard to the viewport ('fixed') or scrolls along with the document ('scroll').

Even if the image is fixed, it is still only visible when it is in the background, padding or border area of the element. Thus, unless the image is tiled ('background-repeat: repeat'), it may be invisible.


This example creates an infinite vertical band that remains "glued" to the viewport when the element is scrolled.

  background: red url("pendant.gif");
  background-repeat: repeat-y;
  background-attachment: fixed;

User agents may treat 'fixed' as 'scroll'. However, it is recommended they interpret 'fixed' correctly, at least for the HTML and BODY elements, since there is no way for an author to provide an image only for those browsers that support 'fixed'. See the section on conformance [add ref] for details.

3.5. The 'background-position' property

Name: background-position
Value: [ [<percentage> | <length> ]{1,2} | [ [top | center | bottom] || [left | center | right] ] ] | inherit
Initial: 0% 0%
Applies to: block-level and replaced elements
Inherited: no
Percentages: refer to the size of the box itself
Media: visual

If a background image has been specified, this property specifies its initial position. Values have the following meanings:

<percentage> <percentage>
With a value pair of '0% 0%', the upper left corner of the image is aligned with the upper left corner of the box's padding edge. [modify; see 'background-origin'] A value pair of '100% 100%' places the lower right corner of the image in the lower right corner of padding area. With a value pair of '14% 84%', the point 14% across and 84% down the image is to be placed at the point 14% across and 84% down the padding area.
<length> <length>
With a value pair of '2cm 2cm', the upper left corner of the image is placed 2cm to the right and 2cm below the upper left corner of the padding area.
'top left' and 'left top'
Same as '0% 0%'.
'top', 'top center', and 'center top'
Same as '50% 0%'.
'right top' and 'top right'
Same as '100% 0%'.
'left', 'left center', and 'center left'
Same as '0% 50%'.
'center' and 'center center'
Same as '50% 50%'.
'right', 'right center', and 'center right'
Same as '100% 50%'.
'bottom left' and 'left bottom'
Same as '0% 100%'.
'bottom', 'bottom center', and 'center bottom'
Same as '50% 100%'.
'bottom right' and 'right bottom'
Same as '100% 100%'.

If only one percentage or length value is given, it sets the horizontal position only, the vertical position will be 50%. If two values are given, the horizontal position comes first. Combinations of length and percentage values are allowed, (e.g., '50% 2cm'). Negative positions are allowed. Keywords cannot be combined with percentage values or length values (all possible combinations are given above).


BODY { background: url("banner.jpeg") right top }    /* 100%   0% */
BODY { background: url("banner.jpeg") top center }   /*  50%   0% */
BODY { background: url("banner.jpeg") center }       /*  50%  50% */
BODY { background: url("banner.jpeg") bottom }       /*  50% 100% */

If the background image is fixed within the viewport (see the 'background-attachment' property), the image is placed relative to the viewport instead of the element's padding area. For example,


  background-image: url("logo.png");
  background-attachment: fixed;
  background-position: 100% 100%;
  background-repeat: no-repeat;

In the example above, the (single) image is placed in the lower-right corner of the viewport.

3.6. The 'background-clip' property

Name: background-clip
Value: border | padding
Initial: border
Applies to: block-level and replaced elements
Inherited: no [yes?]
Percentages: N/A
Media: visual

Determines whether the background extents into the border area or not. If the value is 'padding', the background is clipped to the padding edge and the background of the border is transparent.

3.7. The 'background-origin' property

Name: background-origin
Value: border | padding | content
Initial: padding
Applies to: block-level and replaced elements
Inherited: no [yes?]
Percentages: N/A
Media: visual

Determines how the 'background-position' is calculated. With a value of 'padding', the position is relative to the padding edge ('0 0' is the upper left corner of the padding edge, 100% 100% is the lower right corner). 'Border' means the position is relative to the border edge, and 'content' means relative to the content edge.

Note that in CSS level 2, the position is always relative to the padding edge ('padding'), while in level 1 it is relative to the content edge ('content').

3.8. The 'background' property

Name: background
Value: [<'background-color'> || <'background-image'> || <'background-repeat'> || <'background-attachment'> || <'background-position'>] | inherit
Initial: not defined for shorthand properties
Applies to: all elements
Inherited: no
Percentages: allowed on 'background-position'
Media: visual

The 'background' property is a shorthand property for setting the individual background properties (i.e., 'background-color', 'background-image', 'background-repeat', 'background-attachment' and 'background-position') at the same place in the style sheet.

The 'background' property first sets all the individual background properties to their initial values, then assigns explicit values given in the declaration.


In the first rule of the following example, only a value for 'background-color' has been given and the other individual properties are set to their initial value. In the second rule, all individual properties have been specified.

BODY { background: red }
P { background: url("chess.png") gray 50% repeat fixed }

Note that 'background-clip' and 'background-origin' cannot be set with the 'background' shorthand.

4. Profiles

Each specification using W3C background functionality must define the subset of such functionality it allows and excludes, and describe the local meaning of all the components of that subset.

More information here in the future.

5. Conformance

This section will define conformance with the present specification only.

The inability of a user agent to implement part of this specification due to the limitations of a particular device does not imply non-conformance.

User agents must observe the rules for handling parsing errors.

6. Tests

This specification will contain a test suite allowing user agents to verify their basic conformance to the specification. This test suite does not pretend to be exhaustive and does not cover all possible combined cases of W3C background functionality.

7. Acknowledgements

This specification is the product of the W3C Working Group on Cascading Style Sheets and Formatting Properties. In addition to the editor of this specification, the members of the Working Group are:

A number of invited experts to the Working Group have significantly contributed to CSS 3 : David. L Baron, Todd Fahrner, Daniel Glazman, Ian Hickson, Eric Meyer (The OPAL Group), Jeff Veen.

Former members of the Working Group:

8. References

Håkon Wium Lie; Bert Bos. Cascading Style Sheets, level 1. 1996. W3C Recommendation. Revised 11 Jan 1999. URL: http://www.w3.org/TR/REC-CSS1
Bert Bos; Håkon Wium Lie; Chris Lilley; Ian Jacobs. Cascading Style Sheets, level 2. 1998. W3C Recommendation. URL: http://www.w3.org/TR/REC-CSS2
Bert Bos. CSS3 module: box model. 26 July 2001. W3C working draft. (Work in progress.) URL: http://www.w3.org/TR/2001/WD-css3-box-20010726
Eric A. Meyer; Bert Bos. Introduction to CSS3. 23 May 2001. W3C working draft. (Work in progress.) URL: http://www.w3.org/TR/css3-roadmap