- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Style backgroundSize Property
The HTML DOM style background-size property is used to set or get the size of background image.
Syntax
Following is the syntax for −
Setting the backgroundSize property −
object.style.backgroundSize = "auto|length|cover|contain|intial|inherit"
Properties
The above properties are explained as follows −
Sr.No | Properties & Description |
---|---|
1 | auto The background image displays at full size and it is the default value. |
2 | length For setting the width and height of the background image. The first value is for width and the second is for height. If only one value is given then the missing value defaults to auto. |
3 | percentage For setting the width and height of the background image in percentage. The percentage is calculated based on parents height and width. The first value sets the width, the second value sets the height. If only one value is given then the missing value defaults to auto. |
4 | cover For scaling the background image to be as large to cover the complete background area. |
5 | contain To scale the image so that its height and width can fit inside the content area. |
6 | initial For setting this property to initial value. |
7 | inherit To inherit the parent property value |
Example
Let us look at the example for the HTML DOM style backgroundSize property −
<!DOCTYPE html> <html> <head> <style> #DIV1{ box-shadow: 0 2px 0 4px mintcream; padding: 45px; background: url("https://www.tutorialspoint.com/plsql/images/plsql-mini-logo.jpg"); background-size: 150px 150px; } </style> <script> function changeBackSize(){ document.getElementById("DIV1").style.backgroundSize="100px 100px"; document.getElementById("Sample").innerHTML="The background image size is now reduced"; } </script> </head> <body> <h2>PL/SQL Tutorial</h2> <div id="DIV1"></div> <p>Change the background image size for the above div by clicking the below button</p> <button onclick="changeBackSize()">CHANGE SIZE</button> <p id="Sample"></p> </body> </html>
Output
This will produce the following output −
On clicking the CHANGE SIZE button −
Advertisements