You are here: Reference > JavaScript > client-side > HTML DOM > properties > width (embed, iframe, img, table, ...)

width property (embed, iframe, img, table, ...)

Browser support:
Specifies or returns the default width of the element.
This property is deprecated. Use the width style property instead.

Syntax:

object.width;
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:
Number(px)
Integer that specifies the width of the object, in pixels.
percentage
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? yes no

Example HTML code 2:

Recommendation:
<img id="myImage" src="picture.gif" style="height:100px; width:100px" />
Did you find this example helpful? yes no

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? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content