Section 4.10

Forms

15 entries from this section of the HTML Living Standard, in the order the standard presents them.

Read this section of the standard โ†—

All 15 elements together

One small page that uses every element of this section. Turn on Show tags and point at any part of the page: a label tells you which element draws it. Click to jump to that element's details below.

Forms Written for this site

Every element of this section is in the page above. Point at one to find it, click it to read its details.

<form id="signup" class="signup">
  <h1>Join the HTML workshop</h1>

  <fieldset>
    <legend>About you</legend>
    <label for="name">Name</label>
    <input id="name" name="name" required placeholder="Ada Lovelace" autocomplete="name">

    <label for="email">Email</label>
    <input id="email" name="email" type="email" required placeholder="ada@example.com" autocomplete="email">

    <label for="city">City</label>
    <input id="city" name="city" list="cities" placeholder="Start typing...">
    <datalist id="cities">
      <option value="Paris"></option>
      <option value="Lyon"></option>
      <option value="Montreal"></option>
      <option value="Brussels"></option>
    </datalist>
  </fieldset>

  <fieldset>
    <legend>Your workshop</legend>
    <label for="topic">Topic</label>
    <select id="topic" name="topic" required>
      <button type="button"><selectedcontent></selectedcontent></button>
      <option value="">Choose a topic</option>
      <optgroup label="Beginners">
        <option value="html">๐ŸŒฑ HTML basics</option>
        <option value="css">๐ŸŽจ CSS first steps</option>
      </optgroup>
      <optgroup label="Going further">
        <option value="forms">๐Ÿ“ Forms in depth</option>
        <option value="a11y">โ™ฟ Accessibility</option>
      </optgroup>
    </select>

    <label for="seats">Seats</label>
    <input id="seats" name="seats" type="range" min="1" max="5" value="1">
    <p class="total"><output id="seats-out" for="seats">1</output> seat, total <output id="total" for="seats">20</output> euros</p>

    <label for="notes">Anything to add?</label>
    <textarea id="notes" name="notes" rows="3" placeholder="Allergies, questions..."></textarea>
  </fieldset>

  <div class="gauges">
    <label for="filled">Form completed</label>
    <progress id="filled" max="3" value="0">0 of 3</progress>
    <label for="places">Places already taken</label>
    <meter id="places" min="0" max="30" low="15" high="25" optimum="0" value="24">24 of 30</meter>
  </div>

  <button type="submit">Sign me up</button>
  <p class="thanks" id="thanks" hidden>Thanks! This is a demo, nothing was sent.</p>
</form>

Each element in detail

<form>

Baseline: widely availablesince January 2018

WHATWG User-submittable form

MDN The <form> HTML element represents a document section containing interactive controls for submitting information.

Live preview Example from MDN
<form action="" method="get" class="form-example">
  <div class="form-example">
    <label for="name">Enter your name: </label>
    <input type="text" name="name" id="name" required />
  </div>
  <div class="form-example">
    <label for="email">Enter your email: </label>
    <input type="email" name="email" id="email" required />
  </div>
  <div class="form-example">
    <input type="submit" value="Subscribe!" />
  </div>
</form>

Content model

Categories
flow; palpable
Parents
flow
Children
flow*
Interface
HTMLFormElement

Browser support

First browser version supporting <form>
Chrome 1
Edge 12
Firefox 1
Safari 3
Chrome Android 18
Safari iOS 2

First version with support, from MDN browser-compat-data.

Attributes

accept-charset
Character encodings to use for form submission Value: ASCII case-insensitive match for "UTF-8"
autocomplete
Default setting for autofill feature for controls in the form Value: "on"; "off"
method
Variant to use for form submission Value: "get"; "post"; "dialog"
name
Name of form to use in the document.forms API Value: Text*
novalidate
Bypass form control validation for form submission Value: Boolean attribute
rel
Not described in the WHATWG attribute index: follow the link to its definition.

Also accepts the global attributes.

<label>

Baseline: widely availablesince January 2018

WHATWG Caption for a form control

MDN The <label> HTML element represents a caption for an item in a user interface.

Live preview Example from MDN
<div class="preference">
  <label for="cheese">I like cheese.</label>
  <input type="checkbox" name="cheese" id="cheese" />
</div>

<div class="preference">
  <label for="peas">I like peas.</label>
  <input type="checkbox" name="peas" id="peas" />
</div>

Content model

Categories
flow; phrasing; interactive; palpable
Parents
phrasing
Children
phrasing*
Interface
HTMLLabelElement

Browser support

First browser version supporting <label>
Chrome 1
Edge 12
Firefox 1
Safari โ‰ค4
Chrome Android 18
Safari iOS โ‰ค3.2

First version with support, from MDN browser-compat-data.

Attributes

for
Associate the label with form control Value: ID*

Also accepts the global attributes.

<input>

Baseline: widely availablesince January 2018

WHATWG Form control

MDN The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety of types of input data and control widgets are available, depending on the device and user agent. The <input> element is one of the most powerful and complex in all of HTML due to the sheer number of combinations of input types and attributes.

Live preview Example from MDN
<label for="name">Name (4 to 8 characters):</label>

<input
  type="text"
  id="name"
  name="name"
  required
  minlength="4"
  maxlength="8"
  size="10" />

Content model

Categories
flow; phrasing; interactive*; listed; labelable; submittable; resettable; form-associated; palpable*
Parents
phrasing
Children
empty
Interface
HTMLInputElement

Browser support

First browser version supporting <input>
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

Attributes

accept
Hint for expected file type in file upload controls Value: Set of comma-separated tokens* consisting of valid MIME type strings with no parameters or audio/*, video/*, or image/*
alpha
Allow the color's alpha component to be set Value: Boolean attribute
alt
Replacement text for use when images are not available Value: Text*
autocomplete
Hint for form autofill feature Value: Autofill field name and related tokens*
checked
Whether the control is checked Value: Boolean attribute
colorspace
The color space of the serialized color Value: "limited-srgb"; "display-p3"
dirname
Name of form control to use for sending the element's directionality in form submission Value: Text*
disabled
Whether the form control is disabled Value: Boolean attribute
form
Associates the element with a form element Value: ID*
formmethod
Variant to use for form submission Value: "get"; "post"; "dialog"
formnovalidate
Bypass form control validation for form submission Value: Boolean attribute
height
Vertical dimension Value: Valid non-negative integer
list
List of autocomplete options Value: ID*
max
Maximum value Value: Varies*
maxlength
Maximum length of value Value: Valid non-negative integer
min
Minimum value Value: Varies*
minlength
Minimum length of value Value: Valid non-negative integer
multiple
Whether to allow multiple values Value: Boolean attribute
name
Name of the element to use for form submission and in the form.elements API Value: Text*
pattern
Pattern to be matched by the form control's value Value: Regular expression matching the JavaScript Pattern production
placeholder
User-visible label to be placed within the form control Value: Text*
popovertarget
Targets a popover element to toggle, show, or hide Value: ID*
popovertargetaction
Indicates whether a targeted popover element is to be toggled, shown, or hidden Value: "toggle"; "show"; "hide"
readonly
Whether to allow the value to be edited by the user Value: Boolean attribute
required
Whether the control is required for form submission Value: Boolean attribute
size
Size of the control Value: Valid non-negative integer greater than zero
step
Granularity to be matched by the form control's value Value: Valid floating-point number greater than zero, or "any"
type
Type of form control Value: input type keyword
value
Value of the form control Value: Varies*
width
Horizontal dimension Value: Valid non-negative integer

Also accepts the global attributes.

<button>

Baseline: widely availablesince January 2018

WHATWG Button control

MDN The <button> HTML element is an interactive element activated by a user with a mouse, keyboard, finger, voice command, or other assistive technology. Once activated, it then performs an action, such as submitting a form or opening a dialog.

Live preview Example from MDN
<button class="favorite styled" type="button">Add to favorites</button>

Content model

Categories
flow; phrasing; interactive; listed; labelable; submittable; form-associated; palpable
Parents
phrasing; select*
Children
phrasing*
Interface
HTMLButtonElement

Browser support

First browser version supporting <button>
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

Attributes

command
Indicates to the targeted element which action to take. Value: "toggle-popover"; "show-popover"; "hide-popover"; "close"; "request-close"; "show-modal"; a custom command keyword
commandfor
Targets another element to be invoked. Value: ID*
disabled
Whether the form control is disabled Value: Boolean attribute
form
Associates the element with a form element Value: ID*
formmethod
Variant to use for form submission Value: "get"; "post"; "dialog"
formnovalidate
Bypass form control validation for form submission Value: Boolean attribute
name
Name of the element to use for form submission and in the form.elements API Value: Text*
popovertarget
Targets a popover element to toggle, show, or hide Value: ID*
popovertargetaction
Indicates whether a targeted popover element is to be toggled, shown, or hidden Value: "toggle"; "show"; "hide"
type
Type of button Value: "submit"; "reset"; "button"
value
Value to be used for form submission Value: Text

Also accepts the global attributes.

<select>

Baseline: widely availablesince January 2018

WHATWG List box control

MDN The <select> HTML element represents a control that provides a menu of options.

Live preview Example from MDN
<label for="pet-select">Choose a pet:</label>

<select name="pets" id="pet-select">
  <option value="">--Please choose an option--</option>
  <option value="dog">Dog</option>
  <option value="cat">Cat</option>
  <option value="hamster">Hamster</option>
  <option value="parrot">Parrot</option>
  <option value="spider">Spider</option>
  <option value="goldfish">Goldfish</option>
</select>

Content model

Categories
flow; phrasing; interactive; listed; labelable; submittable; resettable; form-associated; palpable
Parents
phrasing
Children
option*; optgroup*; hr*; script-supporting elements*; noscript*; div*; button*
Interface
HTMLSelectElement

Browser support

First browser version supporting <select>
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

Attributes

autocomplete
Hint for form autofill feature Value: Autofill field name and related tokens*
disabled
Whether the form control is disabled Value: Boolean attribute
form
Associates the element with a form element Value: ID*
multiple
Whether to allow multiple values Value: Boolean attribute
name
Name of the element to use for form submission and in the form.elements API Value: Text*
required
Whether the control is required for form submission Value: Boolean attribute
size
Size of the control Value: Valid non-negative integer greater than zero

Also accepts the global attributes.

<datalist>

Limited availability

WHATWG Container for options for combo box control

MDN The <datalist> HTML element contains a set of <option> elements that represent the permissible or recommended options available to choose from within other controls.

Live preview Example from MDN
<label for="ice-cream-choice">Choose a flavor:</label>
<input list="ice-cream-flavors" id="ice-cream-choice" name="ice-cream-choice" />

<datalist id="ice-cream-flavors">
  <option value="Chocolate"></option>
  <option value="Coconut"></option>
  <option value="Mint"></option>
  <option value="Strawberry"></option>
  <option value="Vanilla"></option>
</datalist>

Content model

Categories
flow; phrasing
Parents
phrasing
Children
phrasing*; option*; script-supporting elements*
Interface
HTMLDataListElement

Browser support

First browser version supporting <datalist>
Chrome 20
Edge 12
Firefox 4
Safari 12.1
Chrome Android 33
Safari iOS 12.2

First version with support, from MDN browser-compat-data.

Attributes

No element-specific attribute.

Also accepts the global attributes.

<optgroup>

Baseline: widely availablesince January 2018

WHATWG Group of options in a list box

MDN The <optgroup> HTML element creates a grouping of options within a <select> element.

Live preview Example from MDN
<label for="dino-select">Choose a dinosaur:</label>
<select id="dino-select">
  <optgroup label="Theropods">
    <option>Tyrannosaurus</option>
    <option>Velociraptor</option>
    <option>Deinonychus</option>
  </optgroup>
  <optgroup label="Sauropods">
    <option>Diplodocus</option>
    <option>Saltasaurus</option>
    <option>Apatosaurus</option>
  </optgroup>
</select>

Content model

Categories
none
Parents
select; div*
Children
option*; script-supporting elements*; noscript*; div*; legend*
Interface
HTMLOptGroupElement

Browser support

First browser version supporting <optgroup>
Chrome 1
Edge 12
Firefox 1
Safari โ‰ค4
Chrome Android 18
Safari iOS โ‰ค3.2

First version with support, from MDN browser-compat-data.

Attributes

disabled
Whether the form control is disabled Value: Boolean attribute
label
User-visible label Value: Text

Also accepts the global attributes.

<option>

Baseline: widely availablesince January 2018

WHATWG Option in a list box or combo box control

MDN The <option> HTML element is used to define an item contained in a <select>, an <optgroup>, or a <datalist> element. As such, <option> can represent menu items in popups and other lists of items in an HTML document.

Live preview Example from MDN
<label for="pet-select">Choose a pet:</label>

<select id="pet-select">
  <option value="">--Please choose an option--</option>
  <option value="dog">Dog</option>
  <option value="cat">Cat</option>
  <option value="hamster">Hamster</option>
  <option value="parrot">Parrot</option>
  <option value="spider">Spider</option>
  <option value="goldfish">Goldfish</option>
</select>

Content model

Categories
none
Parents
select; datalist; optgroup; div*
Children
text*; div*; phrasing*
Interface
HTMLOptionElement

Browser support

First browser version supporting <option>
Chrome 1
Edge 12
Firefox 1
Safari โ‰ค4
Chrome Android 18
Safari iOS โ‰ค3.2

First version with support, from MDN browser-compat-data.

Attributes

disabled
Whether the form control is disabled Value: Boolean attribute
label
User-visible label Value: Text
selected
Whether the option is selected by default Value: Boolean attribute
value
Value to be used for form submission Value: Text

Also accepts the global attributes.

<textarea>

Baseline: widely availablesince January 2018

WHATWG Multiline text controls

MDN The <textarea> HTML element represents a multi-line plain-text editing control, useful when you want to allow users to enter a sizeable amount of free-form text, for example a comment on a review or feedback form.

Live preview Example from MDN
<label for="story">Tell us your story:</label>

<textarea id="story" name="story" rows="5" cols="33">
It was a dark and stormy night...
</textarea>

Content model

Categories
flow; phrasing; interactive; listed; labelable; submittable; resettable; form-associated; palpable
Parents
phrasing
Children
text
Interface
HTMLTextAreaElement

Browser support

First browser version supporting <textarea>
Chrome 1
Edge 12
Firefox 1
Safari โ‰ค4
Chrome Android 18
Safari iOS โ‰ค3

First version with support, from MDN browser-compat-data.

Attributes

autocomplete
Hint for form autofill feature Value: Autofill field name and related tokens*
cols
Maximum number of characters per line Value: Valid non-negative integer greater than zero
dirname
Name of form control to use for sending the element's directionality in form submission Value: Text*
disabled
Whether the form control is disabled Value: Boolean attribute
form
Associates the element with a form element Value: ID*
maxlength
Maximum length of value Value: Valid non-negative integer
minlength
Minimum length of value Value: Valid non-negative integer
name
Name of the element to use for form submission and in the form.elements API Value: Text*
placeholder
User-visible label to be placed within the form control Value: Text*
readonly
Whether to allow the value to be edited by the user Value: Boolean attribute
required
Whether the control is required for form submission Value: Boolean attribute
rows
Number of lines to show Value: Valid non-negative integer greater than zero
wrap
How the value of the form control is to be wrapped for form submission Value: "soft"; "hard"

Also accepts the global attributes.

<output>

Baseline: widely availablesince โ‰ค April 2021

WHATWG Calculated output value

MDN The <output> HTML element is a container element into which a site or app can inject the results of a calculation or the outcome of a user action.

Live preview Example from MDN
<input type="range" id="b" name="b" value="50" /> +
<input type="number" id="a" name="a" value="10" /> =
<output id="result" for="a b">60</output>

Content model

Categories
flow; phrasing; listed; labelable; resettable; form-associated; palpable
Parents
phrasing
Children
phrasing
Interface
HTMLOutputElement

Browser support

First browser version supporting <output>
Chrome 10
Edge โ‰ค18
Firefox 4
Safari 7
Chrome Android 18
Safari iOS 7

First version with support, from MDN browser-compat-data.

Attributes

for
Specifies controls from which the output was calculated Value: Unordered set of unique space-separated tokens consisting of IDs*
form
Associates the element with a form element Value: ID*
name
Name of the element to use for form submission and in the form.elements API Value: Text*

Also accepts the global attributes.

<progress>

Baseline: widely availablesince January 2018

WHATWG Progress bar

MDN The <progress> HTML element displays an indicator showing the completion progress of a task, typically displayed as a progress bar.

Live preview Example from MDN
<label for="file">File progress:</label>

<progress id="file" max="100" value="70">70%</progress>

Content model

Categories
flow; phrasing; labelable; palpable
Parents
phrasing
Children
phrasing*
Interface
HTMLProgressElement

Browser support

First browser version supporting <progress>
Chrome 6
Edge 12
Firefox 6
Safari 6
Chrome Android 18
Safari iOS 8

First version with support, from MDN browser-compat-data.

Attributes

value
Current value of the element Value: Valid floating-point number
max
Upper bound of range Value: Valid floating-point number*

Also accepts the global attributes.

<meter>

Baseline: widely availablesince April 2021

WHATWG Gauge

MDN The <meter> HTML element represents either a scalar value within a known range or a fractional value.

Live preview Example from MDN
<label for="fuel">Fuel level:</label>

<meter id="fuel" min="0" max="100" low="33" high="66" optimum="80" value="50">
  at 50/100
</meter>

Content model

Categories
flow; phrasing; labelable; palpable
Parents
phrasing
Children
phrasing*
Interface
HTMLMeterElement

Browser support

First browser version supporting <meter>
Chrome 6
Edge 13
Firefox 16
Safari 6
Chrome Android 18
Safari iOS 10.3

First version with support, from MDN browser-compat-data.

Attributes

value
Current value of the element Value: Valid floating-point number
min
Lower bound of range Value: Valid floating-point number*
max
Upper bound of range Value: Valid floating-point number*
low
High limit of low range Value: Valid floating-point number*
high
Low limit of high range Value: Valid floating-point number*
optimum
Optimum value in gauge Value: Valid floating-point number*

Also accepts the global attributes.

<fieldset>

Baseline: widely availablesince January 2018

WHATWG Group of form controls

MDN The <fieldset> HTML element is used to group several controls as well as labels (<label>) within a web form.

Live preview Example from MDN
<form>
  <fieldset>
    <legend>Choose your favorite monster</legend>

    <input type="radio" id="kraken" name="monster" value="K" />
    <label for="kraken">Kraken</label><br />

    <input type="radio" id="sasquatch" name="monster" value="S" />
    <label for="sasquatch">Sasquatch</label><br />

    <input type="radio" id="mothman" name="monster" value="M" />
    <label for="mothman">Mothman</label>
  </fieldset>
</form>

Content model

Categories
flow; listed; form-associated; palpable
Parents
flow
Children
legend*; flow
Interface
HTMLFieldSetElement

Browser support

First browser version supporting <fieldset>
Chrome 1
Edge 12
Firefox 1
Safari โ‰ค4
Chrome Android 18
Safari iOS โ‰ค3.2

First version with support, from MDN browser-compat-data.

Attributes

disabled
Whether the descendant form controls, except any inside legend, are disabled Value: Boolean attribute
form
Associates the element with a form element Value: ID*
name
Name of the element to use for form submission and in the form.elements API Value: Text*

Also accepts the global attributes.

<legend>

Baseline: widely availablesince January 2018

WHATWG Caption for fieldset

MDN The <legend> HTML element represents a caption for the content of its parent <fieldset>.

Live preview Example from MDN
<fieldset>
  <legend>Choose your favorite monster</legend>

  <input type="radio" id="kraken" name="monster" value="K" />
  <label for="kraken">Kraken</label><br />

  <input type="radio" id="sasquatch" name="monster" value="S" />
  <label for="sasquatch">Sasquatch</label><br />

  <input type="radio" id="mothman" name="monster" value="M" />
  <label for="mothman">Mothman</label>
</fieldset>

Content model

Categories
none
Parents
fieldset; optgroup
Children
phrasing*; heading content
Interface
HTMLLegendElement

Browser support

First browser version supporting <legend>
Chrome 1
Edge 12
Firefox 1
Safari 3
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

Attributes

No element-specific attribute.

Also accepts the global attributes.

<selectedcontent>

Limited availability

WHATWG Mirrors content from an option

MDN The <selectedcontent> HTML is used inside a <select> element to display the contents of its currently selected <option> within its first child <button>. This enables you to style all parts of a <select> element, referred to as "customizable selects".

Content model

Categories
none
Parents
button
Children
empty
Interface
HTMLSelectedContentElement

Browser support

First browser version supporting <selectedcontent>
Chrome 135
Edge 135
Firefox No
Safari 27
Chrome Android 135
Safari iOS 27

First version with support, from MDN browser-compat-data.

Attributes

No element-specific attribute.

Also accepts the global attributes.