👀 Live Preview
<select size="4"> showing four visible options:
Six options exist, but only four rows are visible without scrolling inside the list box.

The size attribute controls how much of a form control is visible before scrolling. On <select>, it sets the number of visible option rows in a list box. On text-like <input> elements, it sets the approximate width in characters. It is not the same as the responsive sizes attribute on <img> or deprecated <font size> markup.
Visible rows.
Char width.
size > 1.
Different attr.
.size property.
Modern layout.
sizeThe purpose of the size attribute is to give authors a simple HTML-level control over how much of a form field is shown. For a <select>, a higher size turns the control from a compact dropdown into a scrollable list box that displays multiple options at once—useful for picking from long lists without opening a menu.
For <input type="text"> and similar types, size hints how many characters wide the field should appear. Browsers approximate this using the current font; for precise layout, CSS width is usually better.
size on forms is unrelated to text font size or the sizes attribute used with srcset on images. Those are separate features with similar names.
Set size to a positive integer on <select> or supported <input> types:
<!-- List box: 5 visible rows -->
<select size="5">...</select>
<!-- Text input ~30 characters wide -->
<input type="text" size="30"><select>: default is 1 (dropdown). Values > 1 show a list box.<input>: applies to text, search, tel, url, email, and password.size is omitted.<label> and consider multiple for multi-select lists.The size attribute accepts an integer. Meaning depends on the element:
size="1" on <select> — Standard single-line dropdown (default).size="5" on <select> — List box showing five option rows at once.size="20" on <input type="text"> — Field roughly 20 characters wide.size="50" on <input type="email"> — Wider email field hint.<select size="4" multiple>
<option>Red</option>
<option>Green</option>
<option>Blue</option>
<option>Yellow</option>
<option>Purple</option>
</select>| Element | size meaning | Example |
|---|---|---|
<select> | Visible option rows | size="5" |
<input type="text"> | Width in characters | size="30" |
<input type="email"> | Width in characters | size="40" |
| Default select | 1 (dropdown) | Collapsed menu |
| JavaScript | element.size = n | Dynamic update |
| Not for | <img sizes> | Different attribute |
| Element | Supported? | Notes |
|---|---|---|
<select> | Yes | Visible rows in list box mode |
<input type="text"> | Yes | Character width hint |
<input type="email">, etc. | Yes | search, tel, url, password |
<input type="number"> | No | Use CSS width instead |
<textarea> | No | Use rows and cols |
<img> | No | Use sizes with srcset (different attribute) |
size vs sizes vs CSS width| Feature | size | sizes | CSS width |
|---|---|---|---|
| Used on | select, input | img, source | Any element |
| Purpose | Visible rows or char width | Responsive image slot sizes | Exact layout sizing |
| Unit | Integer count | Media condition list | px, %, rem, etc. |
| Use today? | Yes for forms | Yes for images | Preferred for precise UI |
select list box with five visible rows, input character width, and dynamic element.size in JavaScript.
<select size="4"> showing four visible options:
Six options exist, but only four rows are visible without scrolling inside the list box.
Display five options at once in a scrollable list:
<select size="5">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
<option value="option4">Option 4</option>
<option value="option5">Option 5</option>
<option value="option6">Option 6</option>
</select>With size="5", the browser renders a list box instead of a collapsed dropdown. Users see five options immediately and scroll for the rest.
Set visible width on a text field with size:
<label for="username">Username:</label>
<input type="text" id="username" name="username" size="30">size="30" is a hint to the browser about display width. It does not set maxlength—add maxlength separately if you need to cap input length.
Adjust visible rows at runtime with the size property:
<select id="dynamicSelect">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
</select>
<script>
document.getElementById("dynamicSelect").size = 3;
</script>HTMLSelectElement.size and HTMLInputElement.size reflect the attribute. Update them when expanding or collapsing option lists based on user actions.
<label for="..."> associations.size values on long lists can clutter the page; consider search/filter UI.<select> list boxes support arrow keys; custom widgets need equivalent behavior.On select or input.
Rows or char width.
Scroll or type freely.
Right-sized visible area.
The size attribute on <select> and text-like <input> elements is supported in all modern browsers.
All major browsers honor size on select and supported input types.
Bottom line: Use size on forms confidently; combine with CSS for responsive layouts.
size > 1 on <select> when showing many options at once helpssize on inputs to match expected content lengthmaxlength when you need to limit typed characterswidth for responsive, pixel-perfect layoutssize with sizes on imagessize on <textarea> (use rows/cols)size limits how much users can type or select<font size> for text stylingThe size attribute is a practical tool for controlling visible form control dimensions in HTML. On <select>, it defines list box height; on text inputs, it hints character width.
Use it to improve form usability, but remember it is not a substitute for maxlength, CSS layout, or the unrelated sizes attribute on responsive images. Test across devices to keep controls comfortable for every user.
sizeBookmark these before sizing your next form.
Visible options
selectIn characters
inputsize > 1
BehaviorDynamic update
DynamicImages differ
Compare<select>, it sets visible option rows in a list box. On text-like <input> elements, it sets approximate character width.<select> and <input> types including text, search, tel, url, email, and password.size controls visible width. maxlength limits how many characters can be entered.element.size = 3 on select or input elements using the reflected IDL property.Practice select size list boxes and input size width in the Try It editor.
5 people found this page helpful