Backgrounds

This page tests the various declarations of the CSS3 Backgrounds and Borders module.

Compatibility

I left the default values out of this table; they’ve been supported forever.

Selector IE 5.5 IE 6 IE 7 IE8 IE9 pr3 FF 3.0 FF 3.5 FF 3.6 FF 4b1 Saf 4.0 Win Saf 5.0 Win Chrome 4 Chrome 5 Opera 10.10 Opera 10.53 Opera 10.60
Multiple background images
No Yes No Yes Yes Yes Yes
 
background-attachment: fixed
No Yes Yes Yes Yes Yes
 
background-attachment: local
No Yes No No Yes Yes No Yes
 
background-repeat: repeat, repeat-x, repeat-y, no-repeat
The traditional values
Yes Yes Yes Yes Yes
 
background-repeat: space
No Yes No No Incorrect Incorrect No Yes
  • Safari 5 and Chrome 5 interpret it as background-repeat: no-repeat.
background-repeat: round
No Yes No No Incorrect Incorrect No Yes
  • Safari 5 and Chrome 5 interpret it as background-repeat: no-repeat.
Selector IE 5.5 IE 6 IE 7 IE8 IE9 pr3 FF 3.0 FF 3.5 FF 3.6 FF 4b1 Saf 4.0 Win Saf 5.0 Win Chrome 4 Chrome 5 Opera 10.10 Opera 10.53 Opera 10.60
background-clip: padding-box
No Yes No Yes -webkit- Yes Yes No Buggy Yes
  • Issues when scrolling in Opera 10.53
background-clip: content-box
No Yes No Yes -webkit- -webkit- No Buggy
  • Issues when scrolling in Opera 10.53
background-origin: border-box
No Yes No Yes -webkit- Yes Yes No Yes
background-origin: content-box
No Yes No Yes -webkit- Yes Yes No Yes
background-size: [length]
No Yes No -moz- Yes -webkit- Yes Yes -o- Yes
background-size: [percentage]
No Yes No -moz- Yes -webkit- Yes Yes -o- Yes
background-size: contain
No Yes No -moz- Yes No Yes Yes No Yes
background-size: cover
No Yes No -moz- Yes No Yes Yes No Yes
border-image
No No -moz- -webkit- -webkit- No Yes

There’s a difference between Chrome Windows and all other browsers, including Chrome Mac. I’m not taking sides right now, although deep in my heart I believe Chrome Windows is right.

Selector IE 5.5 IE 6 IE 7 IE8 IE9 pr3 FF 3.0 FF 3.5 FF 3.6 FF 4b1 Saf 4.0 Win Saf 5.0 Win Chrome 4 Chrome 5 Opera 10.10 Opera 10.53 Opera 10.60

Multiple background images

Assigning more than one background image to an element.

div.multiple {
	background-image: url(../pix/logo_quirksmode.gif), url(../pix/logo_quirksmode_inverted.gif);
	background-repeat: repeat-y;
	background-position: top left, top right;
	width: 385px;
	height: 100px;
	border: 1px solid #000000;
}

All properties can have several values separated by commas. If a property has one value it counts for all background images (repeat-y in the example).

Background image example

This is the example element we're going to use for the next series of tests:

Text to show where the content area starts

It has the following styles; the relevant background-* will be added inline:

div.test {
	background-image: url(/pix/logo_quirksmode.gif);
	border: 5px solid transparent;
	padding: 10px;
	width: 400px;
	height: 52px;
	overflow: auto;
	color: #999999;
	margin: 5px 0;
}

background-attachment

How is the background image attached to its element? Does it scroll with the element, the document, or not at all?

scroll (default)

The background image scrolls with the document. And no, the name of this value has never made any sense, but it seems we’re stuck with it.

Scrollable

Test
Test
Test
Test
Test
Test
Test

fixed

Background is fixed relative to the entire window. The element merely serves as a viewport through which you look at the background image.

In order to see the fixed background in action, scroll the main window slowly.

Scrollable

Test
Test
Test
Test
Test
Test
Test

local

The background scrolls with the element.

Scrollable

Test
Test
Test
Test
Test
Test
Test

background-repeat

How does the background repeat? Horizontally, vertically, not at all, or does it try to cover the box with a whole number of iterations?

repeat (default)

The image repeats unchecked.

repeat-x

The image repeats only horizontally.

repeat-y

The image repeats only vertically.

no-repeat

The image does not repeat.

space

The image repeats, but only as many times as it fits the box completely After that, the repeats are spaced evenly across the box.

Normal

-moz-

-webkit-

-o-

round

The image repeats, but if it does not fit the box a whole number of times, it is reduced in size until it does.

Normal

-moz-

-webkit-

-o-

background-clip

Which area does the background image fill? The padding box, the content box, or the border box? Remove border for a good idea of what’s going on.

border-box (default)

The background fills the border box.

Normal

-moz-

-webkit-

-o-

padding-box

The background fills the padding box.

Normal

-moz-

-webkit-

-o-

content-box

The background fills the content box.

Normal

-moz-

-webkit-

-o-

background-origin

Where does the background image originate? In the padding box, the content box, or the border box?

padding-box (default)

The background originates in the padding box.

Normal

-moz-

-webkit-

-o-

border-box

The background originates in the border box.

Normal

-moz-

-webkit-

-o-

content-box

The background originates in the content box.

Normal

-moz-

-webkit-

-o-

background-size

What is the size of the background image? You can specify it in pixels, percentages, or scale it to fit the box.

auto (default)

The background image is sized normally.

Normal

-moz-

-webkit-

-o-

length

The background image’s size is determined by this property (50px 20px in the example).

Normal

-moz-

-webkit-

-o-

percentage

The background images’s size is determined by this property (50% 10% in the example). Effectively, this allows you to state how many times the background image is shown, though resizing will occur.

Normal

-moz-

-webkit-

-o-

contain

The image is scaled to the largest size that allows it to fit in the box, while retaining proper aspect ratio.

Normal

-moz-

-webkit-

-o-

cover

The image is scaled to the largest size that allows it to cover the box completely, while retaining proper aspect ratio.

Normal

-moz-

-webkit-

-o-

Border images

Using an image for the border.

Normal

-moz-

-webkit-

-o-

-ms-

Chrome note

There’s a difference between Chrome Windows on the one hand, and all other browsers, including Chrome Mac, on the other. That would usually mean that Chrome Windows is wrong and the others are right, but I think its take on this example is the correct one. So I’m undecided.

Border-image in Chrome 5 Windows