HTML DOM Style backgroundRepeat Property


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.NoValue & Description
1repeat
This is the default value. It repeats the background image vertically and horizontally both.
2repeat-x
This repeats the background image horizontally only.
3repeat-y
This repeats the background image vertically only
4no-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 −

Updated on: 20-Aug-2019

21 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements