HTML | DOM Style backgroundRepeat Property

The backgroundRepeat property in HTML DOM is used to set or return the CSS backgroundRepeat property. It also checks whether the background-image is repeated or not.

Syntax:

  • It is used to returns the backgroundRepeat property.
    object.style.backgroundRepeat 
  • It is used to set the backgroundRepeat property.
    object.style.backgroundRepeat = "repeat|repeat-x|repeat-y|
    no-repeat|initial|inherit" 

Property Values:

  • repeat: It is used to repeat the background image both horizontally and vertically. It is the default value.
  • repeat-x: It is used to repeat the background image horizontally.
  • repeat-y: It is used to set the background image repeated only vertically.
  • no-repeat: It does not repeat the background image. It displays the background image only once.

Return Value: It returns a string value which represent how to background image repeated.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            DOM Style background-repeat property
        </title
          
        <style
            body { 
                background-image: url( 
                background-size: 200px 150px; 
                text-align:center; 
            
        </style
    </head
      
    <body
        <h1>GeeksforGeeks</h1
          
        <h2>
            DOM Style backgroundRepeat Property
        </h2
          
        <button onclick = "myGeeks()">
            Submit
        </button>
          
        <script>
            function myGeeks() {
                document.body.style.backgroundRepeat = "no-repeat";
            
        </script>
    </body
</html>                                     

chevron_right


Output:
Before Click on the button:

After Click on the button:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            DOM Style background-repeat property
        </title
          
        <style
            body { 
                background-image: url( 
                background-repeat: repeat-y; 
                background-size: 200px 150px; 
                text-align:center; 
            
        </style
    </head
      
    <body
        <h1>GeeksforGeeks</h1>
          
        <h2>
            DOM Style backgroundRepeat Property
        </h2
          
        <button onclick = "myGeeks()">
            Submit
        </button>
          
        <script>
            function myGeeks() {
                document.body.style.backgroundRepeat = "repeat-x";
            
        </script>
    </body
</html>                    

chevron_right


Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM Style backgroundRepeat property are listed below:

  • Google Chrome 1.0
  • Internet Explorer 4.0
  • Firefox 1.0
  • Opera 1.0
  • Safari 3.5


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.