Copyright ©2001 W3C® (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.
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].
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.
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.
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.
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:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <HTML> <HEAD> <TITLE>Setting the canvas background</TITLE> <STYLE type="text/css"> BODY { background: url("http://style.com/marble.png") } </STYLE> </HEAD> <BODY> <P>My background is marble. </BODY> </HTML>
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 }
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 }
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:
BODY { background: white url("pendant.gif"); background-repeat: repeat-y; background-position: center; }
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.
BODY { 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.
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:
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,
BODY { 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.
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.
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').
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.
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.
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.
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.
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: