HTML DOM Style backgroundSize Property
-- Learning not just skills, but dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
JavaScript Reference Manual
JavaScript Objects
JavaScript Array Object JavaScript Boolean Object JavaScript Date Object JavaScript Math Object JavaScript Number Object JavaScript String Object JavaScript RegExp Object JavaScript Global Properties/Functions JavaScript Operators JavaScript Error
Browser Objects
Window Object Navigator Object Screen Object History Object Location Object Storage Object
DOM Objects
HTML DOM Document Object HTML DOM Element Object HTML DOM Attribute Object HTML DOM Event Object HTML DOM Console Object CSSStyleDeclaration Object DOM HTMLCollection
HTML Objects
<a> <area> <audio> <base> <blockquote> <body> <button> <canvas> <col> <colgroup> <datalist> <del> <details> <dialog> <embed> <fieldset> <form> <iframe> <frameset > <img> <ins> <input> - button <input> - checkbox <input> - color <input> - date <input> - datetime <input> - datetime-local <input> - email <input> - file <input> - hidden <input> - image <input> - month <input> - number <input> - range <input> - password <input> - radio <input> - reset <input> - search <input> - submit <input> - text <input> - time <input> - url <input> - week <keygen> <link> <label> <legend> <li> <map> <menu> <menuItem> <meta> <meter> <object> <ol> <optgroup> <option> <param> <progress> <q> <script> <select> <source> <style> <table> <td> <th> <tr> <textarea> <title> <time> <track> <video>
Style backgroundSize Property
Example
Specify the size of the background image:
document.getElementById("myDIV").style.backgroundSize="60px 120px";
Definition and Usage
The backgroundSize property sets or returns the size of the background image.
Browser Support
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"
Property Values
| Value | Description |
|---|---|
| auto | Default value. The background image contains its width and height. |
| _length_ | Sets the width and height of the background image. The first sets the width, the second value 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, the second value sets the height. If only one value is given, the second is set to "auto". |
| cover | Keeps the aspect ratio of the image and scales the image to the smallest size to completely cover the background area. Some parts of the background image may not be displayed in the background positioning area. |
| contain | Keeps the aspect ratio of the image and scales the image to the largest size to 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 background-size property of the element. |
| CSS Version: | CSS3 |
Related Articles
CSS Reference: background-size property
YouTip