Definition and Usage
The background-repeat CSS property defines how background images are repeated. A background image can be repeated along the horizontal axis, the vertical axis, both, or not repeated at all. When the repetition of the image tiles doesn't let them exactly cover the background, the way adjustments are done can be controlled by the author: by default, the last image is clipped, but the different tiles can instead be re-sized, or space can be inserted between the tiles.
Note: If the value of this property is not set in a background shorthand property that is applied to the element after the background-repeat CSS property, the value of this property is then reset to its initial value by the shorthand property.
- Initial repeat
- Applies to all elements
- Inherited no
- Media visual
- Computed Value a list, each item consisting of two keywords, one per dimension
- Animatable no
- Canonical order the unique non-ambiguous order defined by the formal grammar
Syntax
Formal syntax: <repeat-style>#
background-repeat: repeat-x /* One-value syntax */
background-repeat: repeat-y
background-repeat: repeat
background-repeat: space
background-repeat: round
background-repeat: no-repeat
background-repeat: repeat space /* Two-value syntax */
background-repeat: repeat repeat
background-repeat: round space
background-repeat: no-repeat round
background-repeat: inherit
Values
- <repeat-style>
- Is following either the one-value syntax - and in that case the values are shorthand for ther two-value equivalent:
repeat-x | is the equivalent of repeat no-repeat |
repeat-y | is the equivalent of no-repeat repeat |
repeat | is the equivalent of repeat repeat |
space | is the equivalent of space space |
round | is the equivalent of round round |
no-repeat | is the equivalent of no-repeat no-repeat |
Or the two-value syntax where the first value represents the horizontal behavior of the repetition and the second value the vertical behavior:repeat | The image is repeated in the given direction as much as needed to cover the whole background image painting area. The last image may be clipped if the whole thing won't fit in the remaining area. |
space | The image is repeated in the given direction as much as needed to cover most of the background image painting area, without clipping an image. The remaining non-covered space is spaced out evenly between the images. The first and last images touches the edge of the element. The value of the background-position CSS property is ignored for the concerned direction, except if one single image is greater than the background image painting area, which is the only case where an image can be clipped when the space value is used. |
round | The image is repeated in the given direction as much as needed to cover most of the background image painting area, without clipping an image. If it doesn't cover exactly the area, the tiles are resized in that direction in order to match it. |
no-repeat | The image is not repeated (and hence the background image painting area will not necessarily been entirely covered). The position of the non-repeated background image is defined by the background-position CSS property. |
Examples
.exampleone {
background-image: url("logo.png");
background-repeat: repeat-x;
}
.exampletwo {
background-image: url("logo.png");
background-repeat: no-repeat;
}
.examplethree {
background-image: url("img1.png"), url("img2.png");
background-repeat: repeat-x, repeat-y;
}
Each image is matched with the corresponding repeat style, from first specified to last.
Compatibility
Desktop browsers
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 4.0 | 3.5 | 1.0 (85) |
Multiple backgrounds | 1.0 | 3.6 (1.9.2) | 9.0 | 10.5 | 1.3 (312) |
Different values for X & Y directions (two-value syntax) | (Yes) | 13.0 | 9.0 | (Yes) | (Yes) |
round and space keywords | Not supported | Not supported (bug 548372) | 9.0 | 10.5 | Not supported |
Mobile browsers
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|
Basic support | NA | NA | NA | NA | NA |
Multiple backgrounds | NA | NA | NA | NA | NA |
Different values for X & Y directions (two-value syntax) | NA | NA | NA | NA | NA |
round and space keywords | NA | NA | NA | NA | NA |