CSS Backgrounds Module Level 4

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-backgrounds-4/
Issue Tracking:
CSSWG Issues Repository
Inline In Spec
Editors:
(W3C)
Elika J. Etemad / fantasai (Apple)
Lea Verou (Invited Expert)
(Invited Expert)
Suggest an Edit for this Spec:
GitHub Editor
Not Ready For Implementation

This spec is not yet ready for implementation. It exists in this repository to record the ideas and promote discussion.

Before attempting to implement this spec, please contact the CSSWG at www-style@w3.org.


Abstract

This module contains the features of CSS relating to the backgrounds of boxes on the page.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-backgrounds” in the title, like this: “[css-backgrounds] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list www-style@w3.org.

This document is governed by the 03 November 2023 W3C Process Document.

1. Introduction

This module is currently maintained as a diff against the parts related to backgrounds of CSS Backgrounds and Borders Module Level 3 [CSS3BG]. We will fold in the text once it’s all formatted up and in CR again, as this will reduce the effort of keeping them in sync (source diffs will be accurate in reflecting the differences).

2. Backgrounds

2.1. Background Positioning: the background-position shorthand property

Name: background-position
Value: <bg-position>#
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Percentages: see individual properties
Computed value: see individual properties
Animation type: see individual properties
Canonical order: per grammar

See [CSS3BG] for definition.

Where

<bg-position> = [  [ left | center | right | top | bottom | start | end | <length-percentage> ]
|
  [ left | center | right | x-start | x-end | <length-percentage> ]
  [ top | center | bottom | y-start | y-end | <length-percentage> ]
|
  [ center | [ left | right | x-start | x-end ] <length-percentage>? ] &&
  [ center | [ top | bottom | y-start | y-end ] <length-percentage>? ]
|
  [ center | [ start | end ] <length-percentage>? ]
  [ center | [ start | end ] <length-percentage>? ]  ]

Values have the following meanings:

One value
If only one value is given, and that value is start or end, then the keyword is duplicated; otherwise the second keyword defaults to center. The resulting value is treated as a two-component value.
More than one value
If the value contains a start or end keyword, then the shorthand sets background-position-inline and background-position-block to the specified values. Otherwise the shorthand sets background-position-x and background-position-y to the specified values.

Specify the value assignment in more detail. Should expand just like Level 3.

Specify what happens to set of properties that are not set. Maybe they’re just not set?

2.1.1. Background Positioning Longhands: the background-position-x, background-position-y, background-position-inline, and background-position-block properties

This section is still being worked out. The tricky thing is making all the start/end keywords work sanely.

Name: background-position-x
Value: [ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#
Initial: 0%
Applies to: all elements
Inherited: no
Percentages: refer to width of background positioning area minus width of background image
Computed value: A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword
Canonical order: per grammar
Animation type: repeatable list
Logical property group: background-position

This property specifies the background position’s horizontal component. An omitted origin keyword is assumed to be left.

Name: background-position-y
Value: [ center | [ [ top | bottom | y-start | y-end ]? <length-percentage>? ]! ]#
Initial: 0%
Applies to: all elements
Inherited: no
Percentages: refer to height of background positioning area minus height of background image
Computed value: A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword
Canonical order: per grammar
Animation type: repeatable list
Logical property group: background-position

This property specifies the background position’s vertical component. An omitted origin keyword is assumed to be top.

Name: background-position-inline
Value: [ center | [ [ start | end ]? <length-percentage>? ]! ]#
Initial: 0%
Applies to: all elements
Inherited: no
Percentages: refer to inline-size of background positioning area minus inline-size of background image
Computed value: A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword
Canonical order: per grammar
Animation type: repeatable list
Logical property group: background-position

This property specifies the background position’s inline-axis component. An omitted origin keyword is assumed to be start.

Name: background-position-block
Value: [ center | [ [ start | end ]? <length-percentage>? ]! ]#
Initial: 0%
Applies to: all elements
Inherited: no
Percentages: refer to size of background positioning area minus size of background image
Computed value: A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword
Canonical order: per grammar
Animation type: repeatable list
Logical property group: background-position

This property specifies the background position’s block-axis component. An omitted origin keyword is assumed to be start.

2.2. Painting Area: the background-clip property

Name: background-clip
Value: <bg-clip>#
Initial: border-box
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: as specified
Canonical order: per grammar
Animation type: repeatable list

Determines the background painting area, which determines the area within which the background is painted. The syntax of the property is given with

<bg-clip> = <visual-box> | border | text

Or should this be defining the -webkit-background-clip property, saying that all the values are identical, with this additional text value?

<visual-box>
The background is painted within (clipped to) the specified box of the element.
text
The background is painted within (clipped to) the intersection of the border box and the geometry of the text in the element and its in-flow and floated descendants.
border
The background is clipped to the area painted by the border, taking border-width and border-style into account but ignoring any transparency introduced by border-color.

2.3. Background Image Layers: the background-tbd shorthand property

Name: background-tbd
Value: <bg-layer>#
Initial: see individual properties
Applies to: all elements
Inherited: no
Percentages: see individual properties
Computed value: see individual properties
Canonical order: per grammar
Animation type: see individual properties

The background-tbd property is a shorthand property that sets all the same properties as the background shorthand except for background-color, allowing authors to easily declare and position background images while letting background-color cascade through independently.

The name of this property is discussed in issue 9083.

This example sets two background layers later in the cascade. By using background-tbd, the previously set background-color won’t be overridden.
p {
  background-color: green;
}

p {
  background-tbd:
    url(a.png) top left,
    url(b.png) top left no-repeat;
}
This example tries to set the background color in addition to the background image. But for that to work, background needs to be used instead of background-tbd. So the background-tbd declaration will be dropped.
p {
  background: url(pass.png) green;   /* valid */
  background-tbd: url(fail.png) red; /* invalid */
}

Should a 'background-repeat: extend' be added?

3. Changes

3.1. Additions since [CSS3BG]

4. Acknowledgments

In addition to the many contributors to the [CSS1], [CSS21], and [CSS3BG] predecessors to this module, the editors would like to thank Tab Atkins, and Håkon Wium Lie for their suggestions and feedback specifically for this Level 4.

Privacy Considerations

No new privacy considerations have been reported on this specification.

Security Considerations

No new security considerations have been reported on this specification.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.


Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-BORDERS-4]
CSS Borders and Box Decorations Module Level 4. Editor's Draft. URL: https://drafts.csswg.org/css-borders-4/
[CSS-BOX-4]
Elika Etemad. CSS Box Model Module Level 4. URL: https://drafts.csswg.org/css-box-4/
[CSS-CASCADE-5]
Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. CSS Cascading and Inheritance Level 5. URL: https://drafts.csswg.org/css-cascade-5/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. URL: https://drafts.csswg.org/css-values-4/
[CSS3BG]
Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. URL: https://drafts.csswg.org/css-backgrounds/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119

Informative References

[CSS1]
Håkon Wium Lie; Bert Bos. Cascading Style Sheets, level 1. 13 September 2018. REC. URL: https://www.w3.org/TR/CSS1/
[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. URL: https://drafts.csswg.org/css2/

Property Index

Name Value Initial Applies to Inh. %ages Anim­ation type Canonical order Com­puted value Logical property group
background-clip <bg-clip># border-box all elements no n/a repeatable list per grammar as specified
background-position <bg-position># see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties
background-position-block [ center | [ [ start | end ]? <length-percentage>? ]! ]# 0% all elements no refer to size of background positioning area minus size of background image repeatable list per grammar A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword background-position
background-position-inline [ center | [ [ start | end ]? <length-percentage>? ]! ]# 0% all elements no refer to inline-size of background positioning area minus inline-size of background image repeatable list per grammar A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword background-position
background-position-x [ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]# 0% all elements no refer to width of background positioning area minus width of background image repeatable list per grammar A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword background-position
background-position-y [ center | [ [ top | bottom | y-start | y-end ]? <length-percentage>? ]! ]# 0% all elements no refer to height of background positioning area minus height of background image repeatable list per grammar A list, each item consisting of: an offset given as a computed <length-percentage> value, plus an origin keyword background-position
background-tbd <bg-layer># see individual properties all elements no see individual properties see individual properties per grammar see individual properties

Issues Index

This module is currently maintained as a diff against the parts related to backgrounds of CSS Backgrounds and Borders Module Level 3 [CSS3BG]. We will fold in the text once it’s all formatted up and in CR again, as this will reduce the effort of keeping them in sync (source diffs will be accurate in reflecting the differences).
Specify the value assignment in more detail. Should expand just like Level 3.
Specify what happens to set of properties that are not set. Maybe they’re just not set?
This section is still being worked out. The tricky thing is making all the start/end keywords work sanely.
Or should this be defining the -webkit-background-clip property, saying that all the values are identical, with this additional text value?
The name of this property is discussed in issue 9083.
Should a 'background-repeat: extend' be added?
MDN

background-position-x

In all current engines.

Firefox49+Safari1+Chrome1+
Opera?Edge79+
Edge (Legacy)12+IE6+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile18+

background-position-y

In all current engines.

Firefox49+Safari1+Chrome1+
Opera?Edge79+
Edge (Legacy)12+IE6+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile?