CSS background-repeat Property
The background-repeat property is used to define how the background image should be repeated. By default, the background image repeats both horizontally and vertically. If the "repeat-x" value is set, the image will be repeated only horizontally. If the "repeat-y" value is set, the image will be repeated only vertically. There are two other values: "space" and "round". "Space" makes the image be repeated without clipping and "round" makes the image be repeated without gaps.
We need to use the background-repeat property with the background-image and background-position properties.
INFO
By default, the image will be displayed in the top left corner without background-position property.
| Initial Value | repeat |
|---|---|
| Applies to | All elements. It also applies to ::first-letter and ::first-line. |
| Inherited | No. |
| Animatable | No. |
| Version | CSS1 |
| DOM Syntax | element.style.backgroundRepeat = "repeat-x"; |
Syntax
Syntax of CSS background-repeat Property
background-repeat: repeat | repeat-x | repeat-y | no-repeat | space | round | initial | inherit;Example of the background-repeat property:
Example of CSS background-repeat Property with repeat value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-image: url("https://www.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
background-repeat: repeat;
}
</style>
</head>
<body>
<h2>This is some heading for an example.</h2>
<p>Some paragraph for an example.</p>
</body>
</html>Result

In the following example, the background-image is not repeated.
Example of the background-repeat property with the "no-repeat" value:
Example of CSS background-repeat Property with no-repeat value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-image: url("https://www.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
background-repeat: no-repeat;
}
</style>
</head>
<body>
<h2>This is some heading for an example.</h2>
<p>Some paragraph for an example.</p>
</body>
</html>In the next example, the background-image is repeated only horizontally.
Example of the background-repeat property with the "repeat-x" value:
Example of CSS background-repeat Property with repeat-x value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-image: url("https://www.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
background-repeat: repeat-x;
}
</style>
</head>
<body>
<h2>This is some heading for an example.</h2>
<p>Some paragraph for an example.</p>
</body>
</html>Here, the "repeat-y" value makes the image be repeated only vertically.
Example of the background-repeat property with the "repeat-y" value:
Example of CSS background-repeat Property with repeat-y value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-image: url("https://www.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
background-repeat: repeat-y;
}
</style>
</head>
<body>
<h2>This is some heading for an example.</h2>
<p>Some paragraph for an example.</p>
</body>
</html>Let’s try an example where the background-image is repeated without clipping.
Example of the background-repeat property with the "space" value:
Example of CSS background-repeat Property with space value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-image: url("https://www.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
background-repeat: space;
}
</style>
</head>
<body>
<h2>This is some heading for an example.</h2>
<p>Some paragraph for an example.</p>
</body>
</html>In the following example, the applied value makes the background-image be repeated without gaps.
Example of the background-repeat property with the "round" value:
Example of CSS background-repeat Property with round value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-image: url("https://www.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
background-repeat: round;
}
</style>
</head>
<body>
<h2>This is some heading for an example.</h2>
<p>Some paragraph for an example.</p>
</body>
</html>Values
| Value | Description | Play it |
|---|---|---|
| repeat | The background image is repeated both horizontally and vertically. This is the default value. | Play it » |
| repeat-x | The background image is repeated only horizontally. | Play it » |
| repeat-y | The background image is repeated only vertically. | Play it » |
| no-repeat | The background image is not repeated. | Play it » |
| space | The background image is repeated as much as possible without clipping. | Play it » |
| round | The background image is repeated without gaps. | Play it » |
| initial | Sets the property to its default value. | Play it » |
| inherit | Inherits the property from its parent element. |
Practice
What are the different values that can be specified for the 'background-repeat' property in CSS?