What are form elements?

Form elements are the controls and helpers used inside forms: <input> (with many types), <textarea>, <select> with <option> and <optgroup>, <button>, <label>, <fieldset> and <legend>, <datalist>, <output>, <progress> and <meter>. Together they collect, describe, group and display user input with built-in accessibility and validation.

The controls

  • <input>: single-line fields and widgets: text, email, password, number, date, checkbox, radio, range, color, file, search, tel, url, hidden.
  • <textarea>: multi-line text; rows, maxlength. CSS field-sizing: content (Baseline 2026) makes it grow with its content.
  • <select>: dropdown or list (multiple, size); <optgroup> groups options. Newer browsers support fully stylable selects with appearance: base-select.
  • <button>: type="submit" (default inside forms), "button", or "reset".

Helpers

  • <label>: names a control; clicking it focuses or toggles the control.
  • <fieldset> + <legend>: groups related controls (radio groups, address blocks); disabled on a fieldset disables everything inside.
  • <datalist>: suggestions for an input (list attribute).
  • <output>: displays a calculation result.
  • <progress> and <meter>: task progress and measurements.

Shared attributes

name, value, required, disabled, readonly, placeholder, autocomplete, autofocus, form (associate a control with a form elsewhere on the page), min/max/step, pattern, minlength/maxlength.

Accessibility basics

Label everything, keep a logical tab order, use autocomplete tokens so browsers can autofill, and announce errors clearly.

Code example

html
1<style>
2 body { font-family: system-ui; }
3 form { display: grid; gap: 10px; max-width: 340px; }
4 textarea { field-sizing: content; min-height: 3lh; } /* grows with content where supported */
5</style>
6<form oninput="total.value = (qty.valueAsNumber || 0) * 25">
7 <label>Full name <input name="name" autocomplete="name"></label>
8 <label>Country
9 <input name="country" list="countries" placeholder="Start typing…">
10 <datalist id="countries"><option value="India"><option value="Germany"><option value="Brazil"></datalist>
11 </label>
12 <label>Size
13 <select name="size">
14 <optgroup label="Regular"><option>S</option><option selected>M</option><option>L</option></optgroup>
15 <optgroup label="Plus"><option>XL</option></optgroup>
16 </select>
17 </label>
18 <label>Quantity <input type="number" id="qty" name="qty" min="1" max="10" value="1"></label>
19 <p>Total: $<output name="total" for="qty">25</output></p>
20 <fieldset><legend>Gift wrap</legend>
21 <label><input type="checkbox" name="wrap"> Add gift wrap</label>
22 </fieldset>
23 <label>Note <textarea name="note"></textarea></label>
24 <label>Upload <progress value="40" max="100">40%</progress></label>
25 <button>Order</button>
26</form>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app