background-repeat
Decides whether and how the background image repeats to fill the element.
- Initial value
repeat- Inherited
- No
- Animatable
- no
- Applies to
- all elements
- JavaScript
element.style.backgroundRepeat = "no-repeat"
Example
#.notebook {
background-image: linear-gradient(transparent 27px, rgba(167, 139, 250, 0.25) 28px);
background-size: 100% 28px;
background-repeat: repeat-y;
line-height: 28px;
}<p class="notebook" style="margin: 0; padding: 0 12px; line-height: 28px; background-image: linear-gradient(transparent 27px, rgba(167,139,250,.25) 28px); background-size: 100% 28px; background-repeat: repeat-y;">Lesson notes:<br>1. A background can be a gradient pattern.<br>2. It repeats vertically like lines in a notebook.</p>Definition and usage
#By default, a background image smaller than the element repeats in both directions like tiles. The background-repeat property lets you turn this off (no-repeat) or limit repetition to one axis (repeat-x, repeat-y).
The space and round values repeat the image without cutting off the last tile: space adds gaps between the copies, and round slightly scales the image so a whole number of copies fits.
For background photos you almost always set no-repeat, and leave repetition for patterns and textures.
Syntax
#background-repeat: repeat | no-repeat | repeat-x | repeat-y | space | round;Values
#Values in practice
#repeat
.demo { background-repeat: repeat; }no-repeat
.demo { background-repeat: no-repeat; }repeat-x
.demo { background-repeat: repeat-x; }space
.demo { background-repeat: space; }round
.demo { background-repeat: round; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Repeating gradients (
repeating-linear-gradient) produce stripe patterns without any image files. - For photos set
no-repeat, otherwise on large screens you will see copies of the image.
Related entries
#Spotted a mistake or missing an example? Write to us.