References

Beginner-friendly references for web development, with live, editable examples.

The HTML size attribute

Attribute All modern browsers
In short

On a text input, the HTML size attribute sets the visible width in characters, 20 by default. A <select> with size="4" becomes a list box showing four rows. Size doesn't limit how much people can type.

Overview

The HTML size attribute sets how big a form control looks, not what it can hold. On an <input> it is a width counted in characters, and on a <select> it is a number of option rows. The value must be a whole number above zero.

The HTML standard applies it to text, search, tel, url, email and password inputs. Chrome ignores it elsewhere, while Firefox still sizes a number input by it. In both, a missing, zero or unreadable size means 20 characters, and the size property reports 20.

A character here means an average one. For size="10", the HTML standard makes the field nine average characters wide plus one of the font's widest. In common proportional fonts such as Arial and Times New Roman, ten M letters overflow that field, while ten digits fit.

A size of 2 or more gives a select that many visible rows in a list box. Without size, a select shows one row, or four with multiple, and its size property returns 0 for historical reasons.

A list box also changes what the form sends. A drop-down selects its first option on its own, but a list box waits for the user, so nothing is submitted for it until someone picks an option. A required list box blocks the form until then.

Syntax

<label for="zip">ZIP code</label>
<input id="zip" name="zip" size="5" maxlength="5">

<label for="day">Delivery day</label>
<select id="day" name="day" size="3">
  <option>Monday</option>
  <option>Wednesday</option>
  <option>Friday</option>
</select>

Values

Value
A positive integer.

Example

Live example
<form id="order">
  <p style="margin:0 0 8px">
    <label for="zip">ZIP code</label>
    <input id="zip" name="zip" size="5" maxlength="5" value="94103">
  </p>
  <p style="margin:0 0 8px">
    <label for="note">Note</label>
    <input id="note" name="note" value="Leave the parcel at the side door">
  </p>
  <label for="day">Delivery day</label><br>
  <select id="day" name="day" size="3">
    <option>Monday</option>
    <option>Wednesday</option>
    <option>Friday</option>
  </select>
  <button>Show form data</button>
  <p id="msg" role="status"></p>
</form>
<p>Press Show form data, then pick a day and press it again.</p>
<script>
const form = document.getElementById('order');
const msg = document.getElementById('msg');
form.addEventListener('submit', function (e) {
  e.preventDefault();
  const data = new FormData(form);
  msg.textContent = data.has('day') ? 'Sends day=' + data.get('day') + '.' : 'No day is sent until you pick one.';
});
</script>

Best practices

  • Use CSS width instead of size when a field has to match your layout exactly. Once CSS sets a width, size no longer changes how wide the field looks.
  • Let a field grow with its text through the CSS field-sizing: content declaration, which overrides size. Chrome and Edge added it in version 123, Firefox in 152 and Safari in 26.2.
  • Preselect the usual choice in a list-box select with selected when the form needs a default.
  • Plan for phones that ignore a select's size. Safari on iOS has no support for it, and Chrome on Android added it in version 142.

Accessibility

The size attribute also changes how a select is exposed to assistive technology. A select shown as a drop-down has the implicit role combobox. A size of 2 or more makes it a list box, whose implicit role is listbox.

Frequently asked questions

Is the size attribute measured in characters or pixels?
On a text input, size counts characters of average width, not pixels. On a select, it counts rows of options.
Can people type more characters than size shows?
Yes, size only sets how wide the field looks, and people can type well past it. The maxlength attribute is what limits how many characters the field accepts.
Can size set the width of a number input?
Not reliably, since size isn't meant for number inputs and browsers differ there. Use the CSS width property instead.
How large should size be to show all of a select's options?
Set size to the number of options, plus one for each optgroup label, and every option shows at once. A larger size leaves empty rows below the last option.
Does size on an input change its font size?
No, size sets an input's width in characters and the rows a select shows, not a font size. For text size, use the CSS font-size property, since the font element, which had its own size attribute, is obsolete in HTML.
Which textarea attribute does the job of size?
A textarea uses cols where an input uses size, setting the width in characters. Its height comes from rows, counted in lines.