Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Style backgroundSize property

Style backgroundSize property

Style Object Reference The Style object

Example

Specify the size of the background image:

document.getElementById("myDIV").style.backgroundSize="60px 120px";

Try it »


Definition and Usage

The backgroundSize property sets or returns the size of the background image.


Browser support

Internet Explorer Firefox Opera Google Chrome Safari

IE9+, Firefox, Opera, Chrome, and Safari support the backgroundSize property.


Syntax

Return the backgroundSize property:

object

.style.backgroundSize

Set the backgroundSize property:

object

.style.backgroundSize="auto|

length

|cover|contain|intial|inherit"

Attribute values

Value Description
auto Default value. The background image keeps its original width and height.
length Sets the width and height of the background image. The first sets the width and the second sets the height. If only one value is given, the second is set to "auto".
percentage Sets the width and height of the background image as a percentage of the parent element. The first sets the width and the second sets the height. If only one value is given, the second is set to "auto".
cover The image's aspect ratio is preserved and the image is scaled to the smallest size that will completely cover the background area. Some parts of the background image may not be visible in the background positioning area.
contain The image's aspect ratio is preserved and the image is scaled to the largest size that will fit within the content area.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical Details

Default value: auto
Return Value: A string representing the element's background-size property.
CSS version CSS3

Related Articles

CSS Reference Manual:The background-size property


Style Object Reference The Style object