size (HTML attribute)

Spec
Depr. Version
No HTML 2
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+ CH2+
Full Full Full Full Full

Syntax

size="number"

Description

The size attribute is used to set the width of a text, password or file input field. The length of these fields is determined by the number of characters that should be visible, as Figure 1 shows.

Figure 1. Two inputs, the first with a size of 6, the second with no size specified Two inputs, the first with a size of 6, the second one with no size specified

For all other input types, the size refers to the width of the control in pixels. Given the presentational nature of this attribute, it’s usually best avoided. Instead, use CSS to define field widths using more precise measurements, with the exception of a file input where CSS control over the input’s appearance is severely limited (for very valid security reasons) and the size attribute is your only real option.

Example

Here, the size attribute is set to "6" for a password field that only requires four characters:
<form>
  <label for="pin">Your 4-digit PIN:</label>
  <input type="password" name="pin" id="pin" maxlength="4" size="6"/>
  ⋮
</form>

Value

This attribute takes a number that reflects the field’s width in characters—for example, "5", "10", and so on.

Compatibility

Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full

It causes no compatibility issues, and has excellent support across all tested browsers.

User-contributed notes

Related Products