HTML <input> width attribute
Definition and Usage
width
The attribute specifies the width of the <input> element.
Note:width
The attribute is only related to <input type="image"> Use together.
Tip:It is a good habit to specify the height and width of an image. If these attributes are set, the required space for the image will be reserved when the page is loaded. Without these attributes, the browser cannot understand the size of the image and cannot reserve an appropriate space for it. In the case when the page and the image are loaded, the page layout will change.
Example
Define an image as a submit button with height and width attributes:
<form action="/action_page.php"> <label for="fname">Name:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">Last Name:</label> <input type="text" id="lname" name="lname"><br><br> <input type="image" src="img_submit.gif" alt="submit" width="48" height="48"> </form>
Syntax
<input width="pixels">
Attribute Value
Value | Description |
---|---|
pixels | Specifies the width of the <input> element in pixels (for example, height="100"). |
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | 16.0 | Support | Support |
Note:width
The attribute is a new attribute of the <input> tag in HTML5.