size (HTML attribute)
| Depr. | Version |
|---|---|
| No | HTML 2 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ |
|---|---|---|---|
| Full | Full | Full | Full |
Syntax
Description
The
size attribute is used to set the width of a text
or password input field. The length of these fields is determined by the
number of characters that should be visible, as Figure 1 shows.
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 best avoided.
Instead, use CSS to define field widths using more precise
measurements.
Example
Here, thesize
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 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.0 | 1.5 | 2.0 | 1.3 | 2.0 | 3.0 | 9.2 | 9.5 |
| 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
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.