English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Complete List of HTML Tags

HTML: <input> width attribute

The HTML input width attribute specifies the width of the <input> element. The width attribute is only applicable to <input type="image">. If height and width are set, the space required for the image is reserved when the page is loaded.

 HTML <input> tag

Online Example

Define the image as a submit button, with height and width attributes of45Pixels:

<!DOCTYPE html>
<html>
<head>
<title>HTML: <input> width attribute - 基础教程网(oldtoolbag.com)</title>
<body>
<form action="action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="image" src="img_submit.gif" alt="Submit" width="45"height="45">
</form>
</body>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the width attribute.

Definition and Usage

The width attribute specifies the width of the <input> element.

Note:The width attribute is only applicable to <input type="image">.

Tip:Always specify both the height and width attributes of the image. If height and width are set, the space required for the image is reserved when the page is loaded. However, if these attributes are not set, the browser will not know the size of the image and will not be able to reserve the appropriate space. The effect is that the page layout will change during the loading process (when the image is loaded).

HTML 4.01 between HTML5difference

The width attribute is an HTML5 new attribute of the <input> tag in the <input>.

Syntax

<input width="pixels">

Attribute Value

ValueDescription
pixelsWidth in pixels (for example width="100").
 HTML <input> tag