CSS background-repeat Property
Last Updated :
23 Aug, 2024
The background-repeat property in CSS is used to repeat the background image both horizontally and vertically. It also decides whether the background-image will be repeated or not.
Syntax:
background-repeat: repeat|repeat-x|round|space|repeat-y|no-repeat|initial|
inherit;
Default Value: Its default value is initial.Â
Property Values:
- repeat: This property is used to repeat the background image both horizontally and vertically. The last image will be clipped if it is not fit in the browser window.Â
- repeat-x: This property is used to repeat the background image horizontally.Â
- repeat-y: This property is used to set the background image repeated only vertically.Â
- no-repeat: This property does not repeat the background image. It displays the background image only once.Â
Example: In this example, we are using the background-repeat: repeat; property.
HTML
<!DOCTYPE html>
<html>
<head>
<title>background-repeat property</title>
<style>
body {
background-image: url(
"https://media.geeksforgeeks.org/wp-content/uploads/geeks-25.png");
background-repeat: repeat;
background-size: 200px 150px;
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>background-repeat: repeat;</h2>
</body>
</html>
Output:Â

Example: Â In this example, we are using the background-repeat: repeat-x; property.
HTML
<!DOCTYPE html>
<html>
<head>
<title>background-repeat property</title>
<style>
body {
background-image: url(
"https://media.geeksforgeeks.org/wp-content/uploads/geeks-25.png");
background-repeat: repeat-x;
background-size: 200px 150px;
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>background-repeat: repeat-x;</h2>
</body>
</html>
Output:Â
Â
Example: Â In this example, we are using the background-repeat: repeat-y; property.
HTML
<!DOCTYPE html>
<html>
<head>
<title>background-repeat property</title>
<style>
body {
background-image: url(
"https://media.geeksforgeeks.org/wp-content/uploads/geeks-25.png");
background-repeat: repeat-y;
background-size: 200px 150px;
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>background-repeat: repeat-y;</h2>
</body>
</html>
Output:Â

Example: Â In this example, we are using the background-image: no-repeat; property.
HTML
<!DOCTYPE html>
<html>
<head>
<title>background-repeat property</title>
<style>
body {
background-image: url(
"https://media.geeksforgeeks.org/wp-content/uploads/geeks-25.png");
background-repeat: no-repeat;
background-size: 400px 250px;
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>background-repeat: no-repeat;</h2>
</body>
</html>
Output:Â

Supported Browsers: The browsers supported by background-repeat property are listed below:Â Â
- Google Chrome 1.0 and above
- Edge 12.0 and above
- Firefox 1.0 and above
- Opera 3.5 and above
- Apple Safari 1.0 and above
CSS background-repeat Property – FAQs
What is the background-repeat property in CSS?
The background-repeat property in CSS controls how a background image repeats (tiles) within an element. You can specify whether the image should repeat horizontally, vertically, both, or not at all.
What is the purpose of background-repeat: repeat-x and repeat-y?
The values repeat-x and repeat-y allow you to control the repetition of a background image along the x-axis (horizontal) or y-axis (vertical) respectively. For example, repeat-x repeats the image only horizontally.
How does background-repeat work with multiple background images?
You can control the repeat behavior of multiple background images by specifying each repeat setting in the order of the images. For example: background-repeat: no-repeat, repeat;.
Why does my background image look distorted when repeating?
Distortion occurs when the image is scaled or stretched due to conflicting background-size settings. Ensure the image dimensions are appropriate for the repeat pattern and consider adjusting background-size to prevent distortion.
How can I stop a background image from repeating?
To prevent a background image from repeating, use background-repeat: no-repeat;. This will display the image once without tiling.