The size
attribute on <input> sets the character width of the element.
On a <select> element it defines the number of items that are visible.
A size attribute on an <input> element.
The textbox is 25 characters wide, i.e. 25 characters are visible.
<label for="firstname">First name</label><br/>
<input type="text" size="25"
name="firstname" value="Josephine" >
For additional details see our HTML input size Reference.
On an <input> tag, the size
attribute defines the element's width.
The width is not expressed in pixels, but in terms of number of characters.
This size
attribute only applies to these <input> types:
On a <select> tag, the size
attribute defines the number of visible options.
<tagname size="number">
Value | Description |
---|---|
number |
For an input element, the element's width in number of characters. For a select element, the number of visible options. |
These elements accept the size
attribute.
Elements | Description | |
---|---|---|
<input> | Specifies an input field -- see example above | |
<select> | Creates a dropdown control. |
A <select> tag with a size value of 4.
The control appears as a scrollable list with 4 options that are visible.
<form action="/tutorial/action.html">
<label for="color">Select a color</label>
<select name="color" id="color" size="4">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="orange">Orange</option>
<option value="purple">Purple</option>
<option value="yellow">Yellow</option>
<option value="brown">Brown</option>
<option value="black">Black</option>
</select><br />
<button type="submit">Submit</button>
</form>
For additional details see our HTML select size Reference.
Here is when size
support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |