HTML <input> widthAttribute
Examples
Define an image as a submit button, with height and width attributes:
<form action="demo_form.html">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="image" src="img_submit.gif.html" alt="Submit" width="48" height="48">
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="image" src="img_submit.gif.html" alt="Submit" width="48" height="48">
</form>
Try it Yourself »
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the width attribute.
Definition and Usage
The width attribute specifies the width of the <input> element.
Note:The width attribute only applies to <input type="image">.
Tip:It is a good habit to specify the height and width attributes for images. If these attributes are set, the required space will be reserved for the image when the page loads. Without these attributes, however, the browser cannot know the image dimensions and cannot reserve appropriate space for them. As a result, the page layout may change while the page and image are loading.
Differences between HTML 4.01 and HTML5
The width attribute is a new attribute of the <input> tag in HTML5.
Syntax
<input width="pixels">
Attribute Values
| Value | Description |
|---|---|
| pixels | The width in pixels (for example, width="100"). |
HTML <input> Tag Other Extensions