The style backgroundRepeat property is used to set or get how the background image repeats itself.
Syntax
Following is the syntax for −
Setting the backgroundRepeat property −
object.style.backgroundRepeat = "repeat|repeat-x|repeat-y|no-repeat|initial|inherit"
Values
Following are the above property values −
Sr.No | Value & Description |
---|---|
1 | repeat This is the default value. It repeats the background image vertically and horizontally both. |
2 | repeat-x This repeats the background image horizontally only. |
3 | repeat-y This repeats the background image vertically only |
4 | no-repeat Does not repeats the background image. |
Example
Let us look at an example for the backgroundRepeat property −
<!DOCTYPE html> <html> <head> <style> body { background-image: url("https://www.tutorialspoint.com/power_bi/images/power-bi-minilogo.jpg"); background-repeat: repeat-x; color:black; font-size:20px; } </style> <script> function changeBackRepeat(){ document.body.style.backgroundRepeat="repeat-y"; document.getElementById("Sample").innerHTML="The background image is now repeated vertically"; } </script> </head> <body> <h2>Demo Heading</h2> <p>This is demo text.</p> <p>This is demo text.</p> <p>This is demo text.</p> <p>This is demo text.</p> <p>Change the body background image repeat value by clicking the below button</p> <button onclick="changeBackRepeat()">CHANGE REPEAT</button> <p id="Sample"></p> </body> </html>
Output
This will produce the following output −
On clicking the CHANGE REPEAT button −