Checkboxes, Radio Buttons, and Select Menus

HTML Living Standard

HTML offers different controls for independent options, mutually exclusive choices, and dropdowns. Each uses attributes to decide which values are submitted.

On this page

Check any number of options with checkboxes

Each checkbox has its own checked state. The fieldset groups related controls and its legend names the group. Checked boxes with the same name can contribute multiple values. An unchecked box contributes no entry. In JavaScript read them with FormData.getAll(name).

How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.

<form id="extras-form">
  <fieldset>
    <legend>Extras</legend>
    <label><input type="checkbox" name="extra" value="gift-wrap"> Gift wrap</label>
    <label><input type="checkbox" name="extra" value="note"> Gift note</label>
  </fieldset>
</form>

What to expect Select both. In the console, new FormData(document.querySelector("#extras-form")).getAll("extra") produces ["gift-wrap", "note"]. Uncheck both and it produces [].

Choose one option with radio buttons

Radio buttons with the same name in the same form form a group. Selecting one clears the previous choice. Give each option a distinct value. The checked attribute sets the initial selection.

How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.

<fieldset>
  <legend>Paper size</legend>
  <label><input type="radio" name="size" value="small" checked> Small</label>
  <label><input type="radio" name="size" value="large"> Large</label>
</fieldset>

What to expect Small starts selected. Click Large and Small becomes unselected. In a form, the submission would include size=large.

Choose from a dropdown with <select>

The select holds options. Each option has text the reader sees and a value the form sends. Use a first option with an empty value alongside required for a prompt that needs a real choice. Add multiple only when several selections are appropriate. Each selected option then contributes its own value.

How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.

<form>
  <label for="product">Product</label>
  <select id="product" name="product" required>
    <option value="">Choose a product</option>
    <option value="pen">Pen</option>
    <option value="notebook">Notebook</option>
  </select>
  <button type="submit">Continue</button>
</form>

What to expect The prompt is initially visible, and the browser blocks submission until you choose Pen or Notebook. Choosing Pen sends the value pen.

Official references