CSS background-repeat
The CSS background-repeat
property is used to specify if a background image repeats (tiles) or not, and how it should repeat.
By default, background images repeat horizontally and vertically across the width and height of the background painting area. However, you can change this behavior with the background-repeat
property.
You can stop the image from repeating altogether (so that it only appears once), or you can specify exactly how it repeats, especially when also using the background-position
and/or the background-size
property.
The background-repeat
property can also be used with multiple background images (i.e. if you specify multiple values for the background-image
property).
Syntax
Where
Possible Values
repeat
- Background repeats both horizontally and vertically. Computes to
repeat repeat
. repeat-x
- Background repeats horizontally only. Computes to
repeat no-repeat
. repeat-y
- Background repeats vertically only. Computes to
no-repeat repeat
. no-repeat
- Background is not repeated. Computes to
no-repeat no-repeat
. round
Computes to
round round
.The image is repeated as often as will fit within the background positioning area. If it doesn't fit a whole number of times, it is rescaled so that it does. If the background painting area is larger than the background positioning area, then the pattern repeats to fill the background painting area.
space
Computes to
space space
.The image is repeated as much as possible to fit within the background positioning area without being clipped. The first and last images touch the edges of the area, and whitespace is distributed evenly between the images. The
background-position
property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using space is when there's not enough room to display one image.
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
initial
- Represents the value specified as the property's initial value.
inherit
- Represents the computed value of the property on the element's parent.
unset
- This value acts as either
inherit
orinitial
, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
General Information
- Initial Value
repeat
- Applies To
- All elements
- Inherited?
- No
- Media
- Visual
- Animatable
- No
Example Code
Official Specifications
- CSS Backgrounds and Borders Module Level 3 (W3C Candidate Recommendation 9 September 2014)
- CSS Level 2.1 (W3C Recommendation 07 June 2011)
- CSS Level 1 (W3C Recommendation 17 Dec 1996)