References

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

The HTML multiple attribute

Attribute All modern browsers
In short

Add multiple to an email input, file input or <select>, and it can hold several values. A select or file input then sends each value as its own entry, such as toppings=ham&toppings=basil, while an email input sends one comma-separated string.

Overview

The HTML multiple attribute lets one form control accept more than one value. In the HTML standard, only <input type="email">, <input type="file"> and <select> have it, and each of the three handles it in its own way.

On an email input, people type addresses separated by commas. The browser strips the spaces around each one, so ana@example.com, bo@example.com becomes ana@example.com,bo@example.com, and every address must be valid. A trailing comma counts as an empty address, which fails validation.

On a file input, the picker lets people choose several files at once. A script reads them all from input.files, while input.value names only the first. When the form is sent, each file becomes a separate entry under the input's name.

Most browsers show a multiple select as a scrolling list box rather than a drop-down, four rows tall unless size says otherwise. Unlike a drop-down, it doesn't select its first option for you. Its value property returns only the first selected option's value, and selectedOptions holds them all.

Syntax

<label for="toppings">Toppings (Ctrl or Command to pick more)</label>
<select id="toppings" name="toppings" multiple>
  <option value="ham">Ham</option>
  <option value="olives">Olives</option>
  <option value="basil">Basil</option>
</select>

Values

Value
A boolean attribute that lets the control take more than one value.

Example

Live example
<form id="order">
  <p style="margin:0 0 6px">On a phone, tap toppings. Then press Show.</p>
  <label for="tops">Toppings (Ctrl or Command to pick more)</label>
  <select id="tops" name="toppings" multiple size="3">
    <option value="ham" selected>Ham</option>
    <option value="olives">Olives</option>
    <option value="basil" selected>Basil</option>
    <option value="onion">Onion</option>
    <option value="corn">Corn</option>
  </select>
  <p style="margin:6px 0">
    <label for="cc">Receipt to (comma-separated)</label><br>
    <input type="email" id="cc" name="cc" multiple value="ana@example.com, bo@example.com">
    <button>Show</button>
  </p>
  <p id="out" role="status" style="margin:0;overflow-wrap:anywhere"></p>
</form>
<script>
const form = document.getElementById('order');
const out = document.getElementById('out');
form.addEventListener('invalid', function (e) {
  out.textContent = e.target.labels[0].textContent + ': ' + e.target.validationMessage;
}, true);
form.addEventListener('submit', function (e) {
  e.preventDefault();
  out.textContent = 'Sends ' + new URLSearchParams(new FormData(form));
});
</script>

More Examples

Best practices

  • Add required to a multiple select or file input when at least one choice is needed. With nothing chosen, the field is then missing a value and the form won't submit.
  • Put a multiple file input in a form with method="post" and enctype="multipart/form-data". A GET form would send the file names alone.
  • Hold every address in a multiple email field to one domain with pattern, such as .+@example[.]com. The browser tests each address against the pattern separately.
  • Keep size above 1 on a multiple select, or leave it out. With size 1, some browsers show the options in a box one line tall, which harms usability.

Accessibility

Say in the label that a multiple field takes more than one choice, and how to give it. Give directions such as "separate email addresses with a comma." Avoid adding aria-multiselectable to a select.

Frequently asked questions

How do I make a multiple choice question in HTML?
Use checkboxes that share a name, or a select with multiple, when people may pick several answers. For exactly one answer, use radio buttons, since a radio group allows only one checked button.
How do I read every selected value of a select with multiple?
Read selectedOptions, or call getAll() on a FormData object, to collect every option chosen in a multiple select. The value property returns only the first one.
How are values from a multiple select sent to the server?
A multiple select sends one entry per chosen option, all under the same name, such as toppings=ham&toppings=basil. Server code has to collect every entry with that name, not only the last one.
What keys select more than one option in a multiple select?
In a multiple select, hold Ctrl, or Command on macOS, while you click more options. Shift selects a range, and keyboard methods depend on the browser and operating system.
Can I limit how many options or files multiple allows?
No, multiple has no maximum. Count selectedOptions.length or files.length in script, and pass setCustomValidity() a message when the count is too high.