Image widthProperty
Image Object
Definition and Usage
The width property sets or returns the value of the width attribute of an image.
The width property specifies the width of an image.
Syntax
imageObject.width=pixels
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the width property
Example
Example
Change the height and width of the image:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function changeSize(){
document.getElementById("compman").height="250";
document.getElementById("compman").width="300";
}
</script>
</head>
<body>
<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="Modify image size">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function changeSize(){
document.getElementById("compman").height="250";
document.getElementById("compman").width="300";
}
</script>
</head>
<body>
<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="Modify image size">
</body>
</html>
Try it yourself »
Image Object Other Extensions