CSS Reference ยท Colors and Backgrounds
The background-repeat property
Reference for CSS background-repeat: repeat, no-repeat, repeat-x, repeat-y, space and round, with the two-value syntax, tiling behavior and live examples.
The background-repeat property decides whether a background image is tiled to fill its positioning area, and if so, in which directions and how the tiles are fitted. By default an image repeats both horizontally and vertically, starting from the position set by background-position.
You normally turn repetition off for single pictures (no-repeat) and keep it on for small patterns and textures. The space and round values tile without cutting tiles off at the edge.
.photo { background-repeat: no-repeat; } .pattern { background-repeat: round; }
Try it
Syntax
background-repeat: <repeat-style>#; <repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2} background-repeat: repeat no-repeat; /* x repeats, y does not */ background-repeat: no-repeat, repeat; /* two layers */
- Initial value:
repeat - Applies to: all elements
- Inherited: no
- Animatable: no
- Computed value: a list of two keywords per layer, one for each axis (
repeat-xbecomesrepeat no-repeat)
Values
| Value | Description |
|---|---|
repeat |
Tiles in that direction until the area is covered. The last tile may be clipped. |
no-repeat |
One copy only, placed by background-position. |
repeat-x |
Shorthand for repeat no-repeat: tiles horizontally only. |
repeat-y |
Shorthand for no-repeat repeat: tiles vertically only. |
space |
Tiles as many whole copies as fit, then spreads the leftover space evenly between them. Nothing is clipped. |
round |
Scales the tiles so a whole number of them fits exactly. Nothing is clipped, but the tile size changes (and may distort if only one axis is rounded). |
| Two values | The first is the horizontal behavior, the second the vertical. |
Usage notes
no-repeatis the usual choice for photos. Forgetting it is the classic bug: a small image that suddenly tiles when the box grows.- Gradients tile too. A gradient with no intrinsic size fills the area, so repeating only shows when you shrink it with
background-size. That trick makes stripes and checkerboards from gradients. spaceandroundneed whole tiles. If not even one tile fits,spaceshows one tile androundshrinks or grows it to fit.- Position still matters. With
repeat, the pattern starts at the position and tiles in both directions from there, which is why shifting the position can move the seam. - Order in the shorthand. Within
background, put the repeat keyword anywhere among the other parts, but the position and size pair must stay together with the slash. - Per-layer lists. When you use several images, give a repeat value for each, or the list is repeated to match.
Browser support
All six values are supported in current browsers. space and round are the newest and are missing from very old browsers, so check a compatibility table if you support them.
Related
background-sizeโ shrink tilesbackground-positionโ the tile originbackground-image,background- Lesson: Backgrounds