You are here: Reference > JavaScript > client-side > HTML DOM > properties > width (embed, iframe, img, table, ...)
width property (embed, iframe, img, table, ...)
Specifies or returns the default width of the element.
This property is deprecated. Use the width style property instead.
Syntax:
You can find the related objects in the Supported by objects section below.
HTML page for this property: width |
Possible values:
String that sets or retrieves the width of the object.
One of the following values:
Integer that specifies the width of the object, in pixels. | |||||||
Integer in the range 0-100 followed by a %. |
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the width attribute:
|
||||
<img id="myImage" src="picture.gif" height="100px" width="100px" /> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
Recommendation:
|
||||
<img id="myImage" src="picture.gif" style="height:100px; width:100px" /> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 3:
This example illustrates the use of the width property:
|
||||
<head> <script type="text/javascript"> function SetWidth () { var image = document.getElementById ("myImage"); var input = document.getElementById ("myInput"); image.width = input.value; } </script> </head> <body> <img id="myImage" src="picture.gif" height="100px" width="100px" /> <br /> <input id="myInput" type="text" value="50" /> <button onclick="SetWidth ();">Set image width!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
External links:
width (MSDN)
width (Mozilla Developer Center)
width (Safari Reference Library)
width (HR) (W3C)
width (IFRAME) (W3C)
width (IMG) (W3C)
width (TABLE) (W3C)
width (TH) (W3C)
width (APPLET) (W3C)
width (COL) (W3C)
width (COLGROUP) (W3C)
width (Mozilla Developer Center)
width (Safari Reference Library)
width (HR) (W3C)
width (IFRAME) (W3C)
width (IMG) (W3C)
width (TABLE) (W3C)
width (TH) (W3C)
width (APPLET) (W3C)
width (COL) (W3C)
width (COLGROUP) (W3C)
User Contributed Comments