Style background property
The Style object
Definition and Usage
The background property sets or returns up to five separate background properties in shorthand form.
With this property, you can set/return:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
The properties above can also be set with individual style properties. Using individual properties is strongly recommended for better control.
Syntax
Set the background property:
Object.style.background="
color image repeat attachment position
"
Return the background property:
Object.style.background
**Tip:** The default value of the background property is: transparent none repeat scroll 0% 0%.
| Parameters | Description |
|---|---|
| color | Set the background color of an element |
| image | Set the background image of an element |
| repeat | Set how the background image is repeated |
| attachment | Set whether the background image is fixed or scrolls with the rest of the page |
| position | Set the starting position of the background image |
Browser support





All major browsers support the background attribute.
Example
Example
Set the style of the document background:
Hello World!
Try it »
The Style object