Latest web development tutorials

HTML DOM Image width attribute

Image Object Reference Image Object

Definition and Usage

Value width property sets or returns the picture width properties.

width attribute specifies the width of the image.

grammar

imageObject.width=pixels


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support width attribute


Examples

Examples

Change the picture height and width:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function changeSize(){
    document.getElementById("compman").height="250";
    document.getElementById("compman").width="300";
}
</script>
</head>
<body>

<img id="compman" src="compman.gif" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="修改图像大小">

</body>
</html>

try it"


Image Object Reference Image Object