

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set the size of the background image with JavaScript?
To set the size of the background image in JavaScript, use the backgroundSize property. It allows you to set the image size for the background.
Example
You can try to run the following code to learn how to set the size of the background image:
<!DOCTYPE html> <html> <head> <style> #box { border: 2px dashed blue; width: 600px; height: 400px; background: url('https://www.tutorialspoint.com/videotutorials/images/coding_ground_home.jpg') no-repeat; } </style> </head> <body> <button onclick="display()">Set size of background image</button> <div id="box"> </div> <script> function display() { document.getElementById("box").style.backgroundSize = "150px 200px"; } </script> </body> </html>
- Related Questions & Answers
- How to set the positioning area of the background image with JavaScript?
- How to set the background image for an element with JavaScript DOM?
- Set the Background Image Position with CSS
- Set the background image of an element with CSS
- How to set the painting area of the background with JavaScript?
- How to set the starting position of a background image in JavaScript DOM?
- How to set the widths of the image border with JavaScript?
- How to resize the background image to window size in Tkinter?
- How to set a background image to be fixed with JavaScript DOM?
- How to set the font size of text with JavaScript?
- How to set background image of a webpage?
- How to set the inward offsets of the image border with JavaScript?
- Set a linear gradient as the background image with CSS
- Set a radial gradient as the background image with CSS
- Specify the size of the background images with CSS
Advertisements