HTML DOM Image Width Property - W3Schools
Có thể bạn quan tâm
❮ Image Object
Example
Change the width of an image to 300px:
document.getElementById("myImg").width = "300"; Try it Yourself »Description
The width property sets or returns the value of the width attribute of an image.
The width attribute specifies the width of an image.
This property can also return the width of an image that has been styled with CSS (See More Examples).
Tip: Use the height property to set or return the value of the height attribute of an image.
Browser Support
| Property | |||||
|---|---|---|---|---|---|
| width | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the width property:
imageObject.widthSet the width property:
imageObject.width = pixelsProperty Values
| Value | Description |
|---|---|
| pixels | The width in pixels (e.g. width="100") |
Technical Details
| Return Value: | A Number, representing the width of the image, in pixels |
|---|
More Examples
Example
Return the width of an image:
var x = document.getElementById("myImg").width; Try it Yourself »Example
Change the height and width of an image to 300px:
document.getElementById("myImg").height = "300";document.getElementById("myImg").width = "300"; Try it Yourself »Example
Return the width of an image that has been styled with CSS:
var x = document.getElementById("myImg").width; Try it Yourself »Related Pages
HTML reference: HTML <img> width attribute
❮ Image Object ★ +1 Sign in to track progressTừ khóa » Html Get Original Image Size
-
How To Get Original Image Size (Width & Height) In JavaScript
-
Determine Original Size Of Image Cross Browser? - Stack Overflow
-
How To Get Image Size Using JavaScript - W3docs
-
Get The Size Of An Image - HTML DOM
-
Get Image Original Size Javascript Code Example - Code Grepper
-
How To Check Image Size In Html Code Example
-
How To Resize An Image In HTML?
-
Setting Height And Width On Images Is Important Again
-
HTML Img Width Attribute - W3Schools
-
Photoshop Image Size And Resolution - Adobe Support
-
Change Size Of An Image With JavaScript/jQuery - Techie Delight
-
Getimagesize - Manual - PHP
-
5 Ways To Get Image Width And Height Javascript Examples
-
Responsive Images - Learn Web Development | MDN