First Public Working Draft · css-backgrounds

CSS Backgrounds and Borders

18 properties defined by this specification, 13 of them known to at least one browser (the others are badged Not in any browser yet).

Each feature in detail

background

Property Baseline: widely availablesince January 2018 Modern CSS: background-clip: text

MDN The background CSS shorthand property sets all background style properties at once, such as color, image, origin, size, and repeat method.

Live preview Example from MDN
#example-element {
  min-width: 100%;
  min-height: 100%;
  padding: 10%;
}

Syntax

<bg-layer>#? , <final-bg-layer>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

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
Longhands
background-image, background-position, background-size, background-repeat, background-attachment, background-origin, background-clip, background-color

Browser support

First browser version supporting background
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-attachment

Property Limited availability

MDN The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.

Live preview Example from MDN
body {
  overflow: scroll;
}

#default-example {
  height: 600px;
}

#example-element {
  max-width: 20rem;
  height: 100%;
  background:
    url("https://developer.mozilla.org/shared-assets/images/examples/lizard.png") right 3rem top 1rem / 15rem
      no-repeat,
    url("https://developer.mozilla.org/shared-assets/images/examples/moon.jpg") center / 10rem;
  font-size: 1.2rem;
  font-weight: bolder;
  overflow: auto;
  padding: 20px;
  color: red;
  text-shadow:
    0 0 0.5rem black,
    0 0 0.5rem black;
}

Syntax

<attachment>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
scroll
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
list, each item the keyword as specified
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting background-attachment
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 3.2

First version with support, from MDN browser-compat-data.

background-clip

Property Baseline: widely availablesince January 2018 Modern CSS: background-clip: border-areaModern CSS: background-clip: text

MDN The background-clip CSS property sets whether an element's background extends underneath its border box, padding box, or content box.

Live preview Example from MDN
#example-element {
  background-image: url("https://developer.mozilla.org/shared-assets/images/examples/leopard.jpg");
  color: white;
  text-shadow: 2px 2px black;
  padding: 20px;
  border: 10px dashed #333333;
  font-size: 2em;
  font-weight: bold;
}

Syntax

<bg-clip>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
border-box
Applies to
all elements
Inherited
no
Percentages
n/a
Computed value
as specified
Canonical order
per grammar
Animation type
repeatable list

Browser support

First browser version supporting background-clip
Chrome 1
Edge 12
Firefox 4
Safari 5
Chrome Android 18
Safari iOS 5

First version with support, from MDN browser-compat-data.

background-color

Property Baseline: widely availablesince January 2018

MDN The background-color CSS property sets the background color of an element.

Live preview Example from MDN
#example-element {
  min-width: 100%;
  min-height: 100%;
  padding: 10%;
}

Syntax

<color>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
transparent
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
computed color
Canonical order
per grammar
Animation type
by computed value

Browser support

First browser version supporting background-color
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-image

Property Baseline: widely availablesince January 2018 Modern CSS: image-set()

MDN The background-image CSS property sets one or more background images on an element.

Live preview Example from MDN
#example-element {
  min-width: 100%;
  min-height: 100%;
  padding: 10%;
}

Syntax

<bg-image>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
none
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
list, each item either an <image> or the keyword none
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting background-image
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-origin

Property Baseline: widely availablesince January 2018

MDN The background-origin CSS property sets the background's origin: from the border start, inside the border, or inside the padding.

Live preview Example from MDN
#example-element {
  background-image: url("https://developer.mozilla.org/shared-assets/images/examples/leopard.jpg");
  color: #d73611;
  text-shadow: 2px 2px black;
  padding: 20px;
  border: 10px dashed #333333;
  font-size: 2em;
  font-weight: bold;
}

Syntax

<visual-box>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
padding-box
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
list, each item a keyword as specified
Canonical order
per grammar
Animation type
repeatable list

Browser support

First browser version supporting background-origin
Chrome 1
Edge 12
Firefox 4
Safari 3
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-position

Property Baseline: widely availablesince January 2018

MDN The background-position CSS property sets the initial position for each background image.

Live preview Example from MDN
#example-element {
  background-color: navajowhite;
  background-image: url("https://developer.mozilla.org/shared-assets/images/examples/star.png");
  background-repeat: no-repeat;
  height: 100%;
}

Syntax

<bg-position>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
0% 0%
Applies to
all elements
Inherited
no
Percentages
refer to size of background positioning area minus size of background image; see text
Computed value
a list, each item a pair of offsets (horizontal and vertical) from the top left origin, each offset given as a computed <length-percentage> value
Canonical order
per grammar
Animation type
repeatable list
Longhands
background-position-x, background-position-y

Browser support

First browser version supporting background-position
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-position-block

Property Not in any browser yet

No prose in the spec's definition and no MDN page yet: the spec link below is the only description.

Syntax

[ center | [ [ start | end ]? <length-percentage>? ]! ]#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

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

background-position-inline

Property Not in any browser yet

No prose in the spec's definition and no MDN page yet: the spec link below is the only description.

Syntax

[ center | [ [ start | end ]? <length-percentage>? ]! ]#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

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

background-position-x

Property Baseline: widely availablesince January 2018

MDN The background-position-x CSS property sets the initial horizontal position for each background image. The position is relative to the position layer set by background-origin.

Live preview Example from MDN
#example-element {
  background-color: navajowhite;
  background-image: url("https://developer.mozilla.org/shared-assets/images/examples/star.png");
  background-repeat: no-repeat;
  height: 100%;
}

Syntax

[ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

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

Browser support

First browser version supporting background-position-x
Chrome 1
Edge 12
Firefox 49
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-position-y

Property Baseline: widely availablesince January 2018

MDN The background-position-y CSS property sets the initial vertical position for each background image. The position is relative to the position layer set by background-origin.

Live preview Example from MDN
#example-element {
  background-color: navajowhite;
  background-image: url("https://developer.mozilla.org/shared-assets/images/examples/star.png");
  background-repeat: no-repeat;
  height: 100%;
}

Syntax

[ center | [ [ top | bottom | y-start | y-end ]? <length-percentage>? ]! ]#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

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

Browser support

First browser version supporting background-position-y
Chrome 1
Edge 12
Firefox 49
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-repeat

Property Baseline: widely availablesince March 2019

MDN The background-repeat CSS shorthand property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all.

Live preview Example from MDN
#example-element {
  background: #cccccc url("https://developer.mozilla.org/shared-assets/images/examples/moon.jpg") center /
    120px;
  min-width: 100%;
  min-height: 100%;
}

Syntax

<repeat-style>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
repeat
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
list, each item a pair of keywords, one per dimension
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting background-repeat
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

background-repeat-block

Property Not in any browser yet

No prose in the spec's definition and no MDN page yet: the spec link below is the only description.

Syntax

<repetition>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
repeat
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
as specified
Canonical order
per grammar
Animation type
discrete

background-repeat-inline

Property Not in any browser yet

No prose in the spec's definition and no MDN page yet: the spec link below is the only description.

Syntax

<repetition>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
repeat
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
as specified
Canonical order
per grammar
Animation type
discrete

background-repeat-x

Property Experimental

MDN The background-repeat-x CSS property sets how background images are repeated, or not, along the horizontal axis.

Live preview Example from MDN
#example-element {
  background: #cccccc url("https://developer.mozilla.org/shared-assets/images/examples/moon.jpg") no-repeat
    center / 120px;
  min-width: 100%;
  min-height: 100%;
}

Syntax

<repetition>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
repeat
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
as specified
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting background-repeat-x
Chrome 5, removed in 120
Edge 79, removed in 120
Firefox No
Safari 5, removed in 15
Chrome Android 18, removed in 120
Safari iOS 4.2, removed in 15

First version with support, from MDN browser-compat-data.

background-repeat-y

Property Experimental

MDN The background-repeat-y CSS property sets how background images are repeated, or not, along the vertical axis.

Live preview Example from MDN
#example-element {
  background: #cccccc url("https://developer.mozilla.org/shared-assets/images/examples/moon.jpg") center /
    120px;
  min-width: 100%;
  min-height: 100%;
}

Syntax

<repetition>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
repeat
Applies to
all elements
Inherited
no
Percentages
N/A
Computed value
as specified
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting background-repeat-y
Chrome 5, removed in 120
Edge 79, removed in 120
Firefox No
Safari 5, removed in 15
Chrome Android 18, removed in 120
Safari iOS 4.2, removed in 15

First version with support, from MDN browser-compat-data.

background-size

Property Baseline: widely availablesince January 2018

MDN The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.

Live preview Example from MDN
#example-element {
  background-image: url("https://developer.mozilla.org/shared-assets/images/examples/hand.jpg");
  min-width: 100%;
  min-height: 100%;
}

Syntax

<bg-size>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
auto
Applies to
all elements
Inherited
no
Percentages
see text
Computed value
list, each item a pair of sizes (one per axis) each represented as either a keyword or a computed <length-percentage> value
Canonical order
per grammar
Animation type
repeatable list

Browser support

First browser version supporting background-size
Chrome 3
Edge 12
Firefox 4
Safari 5
Chrome Android 18
Safari iOS 4.2

First version with support, from MDN browser-compat-data.

background-tbd

Property Not in any browser yet

No prose in the spec's definition and no MDN page yet: the spec link below is the only description.

Syntax

<bg-layer>#

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

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