HTML <input> size attribute
Definition and Usage
size
The attribute specifies the visible width of the <input> element (in characters).
Note:size
The attribute applies to the following input types:
- text
- search
- tel
- url
- password
Tip:To specify the maximum number of allowed characters in the <input> element, use maxlength attribute.
Compatibility Tips
Since the size attribute is a visual design attribute, we recommend using CSS instead of it.
CSS Syntax:
<input style="width:100px" />
You can find more about the CSS syntax on CodeW3C.com's CSS tutorial: width attribute details.
Example
An HTML form containing two input fields with widths of 50 and 4 characters each:
<form action="/action_page.php"> <label for="fname">Name:</label> <input type="text" id="fname" name="fname" size="50"><br><br> <label for="pin">PIN:</label> <input type="text" id="pin" name="pin" maxlength="4" size="4"><br><br> <input type="submit" value="Submit"> </form>
Syntax
<input size="number">
Attribute Value
Value | Description |
---|---|
number | Specify the width of the <input> element in characters. The default value is 20. |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |