Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

size — input field or select list size

The size attribute specifies the visible width of a text input in characters or the number of visible select options. It neither limits the value length nor enables multiple selection.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<input type="text" size="20">
<select size="3">...</select>

size is not a global attribute. When present on input or select, its valid value is a positive integer without a unit; 0, negative numbers, and 20px are invalid values.

On input, it applies to text, search, tel, url, email, and password, not number. It specifies how many characters the browser should provide visible space for while editing, not an exact pixel width. The DOM property input.size defaults to 20. size does not limit value length; use maxlength for that.

On select, it specifies how many options to show. size="2" alone does not enable multiple selection: that requires multiple. If the attribute is absent or integer parsing fails, the display size is 4 with multiple, otherwise 1. Do not equate this display size with the default value of the DOM property select.size.

The example separates size from value and selection count: the input has size="4" but stores seven characters, and the list has size="2" while multiple remains false.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>size example</title>
<label>Code <input id="code" type="text" size="4" value="ABCDEFG"></label>
<label>Item
  <select id="item" size="2">
    <option>A</option>
    <option>B</option>
    <option>C</option>
  </select>
</label>
<pre id="result"></pre>
<script>
  const code = document.getElementById('code');
  const item = document.getElementById('item');
  document.getElementById('result').textContent =
    `input.size=${code.size}\ninput.value.length=${code.value.length}\nselect.size=${item.size}\nselect.multiple=${item.multiple}`;
</script>
</html>

Result

input.size=4
input.value.length=7
select.size=2
select.multiple=false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources