Example
Set a background-image to no-repeat:
document.body.style.backgroundRepeat = "repeat-y";
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The backgroundRepeat property sets or returns how to repeat (tile) a background-image.
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
backgroundRepeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntax
Return the backgroundRepeat property:
object.style.backgroundRepeat
Set the backgroundRepeat property:
object.style.backgroundRepeat="repeat|repeat-x|repeat-y|no-repeat|initial|inherit"
Property Values
Value | Description |
---|---|
repeat | The background image is repeated both vertically and horizontally. This is default |
repeat-x | The background image is only repeated horizontally |
repeat-y | The background image is only repeated vertically |
no-repeat | The background-image is not repeated |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | repeat |
---|---|
Return Value: | A String, representing how a background-image is repeated |
CSS Version | CSS1 |
More Examples
Example
Change the backgroundRepeat property of a specified DIV element:
document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";
Try it Yourself »
Example
Set a background-image to repeat horizontally or vertically:
function repeatVer()
{
document.body.style.backgroundRepeat = "repeat-y";
}
function repeatHor() {
document.body.style.backgroundRepeat = "repeat-x";
}
Try it Yourself »
Example
Return the background-repeat value of a document:
alert(document.body.style.backgroundRepeat);
Try it Yourself »
Related Pages
CSS tutorial: CSS Background
CSS reference: background-position property
CSS reference: background-repeat property
HTML DOM reference: background property
< Style Object