This page body contains a single form element containing many fieldset acting as articles; with legend acting as their headings. It lists the elements that traditionally belong within the forms, plus three closely related interactive elements, the latter usually split-off in a separate group - dialog and details with its summary heading. It showcases in particular the input element is declined in many different forms depending one if its 22 possible type values.
form
fieldset
legend
dialog
details
summary
input
type
Form submission sends an HTTP method on the specified action URL, which submission widgets may override with the matching form* attribute. The browsing context to target works as in Links. Flagging the form novalidate skips the client-side check for input type, required, min, max, step, minlength, maxlength and regex pattern (the latter only on input type='text', type='tel', type='email', type='url', type='password', type='search'). A form can handle all descendants oninput or onchange, with the target being the input origin, from the natural event propagation mechanism. The following snippet converts the form data to an object.
method
action
form*
target
novalidate
required
min
max
step
minlength
maxlength
pattern
type='text'
type='tel'
type='email'
type='url'
type='password'
type='search'
oninput
onchange
// when using input [name] const _formNamed = (_) => Object.fromEntries( new FormData(_).entries()); // when using input [id] without [name] const _formElems = (_) => Object.fromEntries( Array.from(_.elements) .filter(_ => _.id) .map(_ => [_.id, _.type === "checkbox" ? _.checked : _.value]));
The form values onreset are those prior to the change, unlike the new values in onchange, using onreset=setTimeout(e => handler(e), 0) uniformizes the handler.
onreset
onreset=setTimeout(e => handler(e), 0)
The autocapitalize and autocomplete attributes assigned at the form parent will get inherited by some children, see Classifications on Form Categories.
autocapitalize
autocomplete
type='color'
list
type='file'
multiple
webkitDirectory
disabled
type='number'
type='range'
type='checkbox'
type='radio'
type='time'
type='date'
type='datetime'
type='datetime-local'
type='month'
type='week'
button
Form submission can occur via four inputs. type='submit' is the first standard way. value accepts the text to display within. No value will display a fallback text.
type='submit'
value
Putting regular buttons in forms can cause unwanted submission. type='button' has no behavior by default, the display text is specified via value, with no fallback. Its use-case is to avoid JS to prevent the event default.
type='button'
type='image' uses an image linked in src, with fallback alt. When both are missing shows the link directly, or if absent "Submit Query" (firefox), or the title (chrome/safari).
type='image'
src
alt
title
type='reset' resets the current values of the form to their original setup, with value specifying the display text, which falls-back to "Reset" on all browsers.
type='reset'
The standard HTML button causes submission, due to its default type='submit'. This can be changed, with the same possible values as buttons made via input.
Article on styling buttons: Rediscovering the Button Element - Kevin Hale, 2007
direction
accent-color
Heading label for the fieldset Displayed top-left within the border, by default. Restricted to being the first element, thus it is restricted to be a singleton (when present). Its role as heading is implicit. It is practical by being depth-agnostic as a section heading, similar to figcaption and caption and unlike the h1-6.
figcaption
caption
h1-6
Used to partition form elements into sections. This page is a collection of field sets. It has a broader usefulness as a general pseudo-section element,
label
Labels provide accessibility by informing users about the nature of associated input.
Association is not only semantic, for example, clicking labels correctly associated to radio inputs will select them as if the input itself was clicked.
textarea
Accepts sizing attributes rows, cols. Escapes < and > symbols: useful to include markup in pages. It can be marked disabled, preventing user edits. This also disables cursor events (highlighting, scrolling, etc.). To prevent user edits while allowing cursor events, mark it readonly="true" instead.
rows
cols
readonly="true"
select
Presents its optgroup and option tree as selectable. Its size is how many choices will be displayed, i.e. sets its the default height. Flag multiple enables multi-selections.
size
size='4'
optgroup
A parent for nested option, provoding both a hierarchical relationship in the DOM and a visual non-selectable, element-like entry acting as a label, within a select field. May be disabled, propagating the status down-to options.
option
A pick for selection in either select or datalist, or grouped within an optgroup in either.
selected
datalist
datalist is used to contain option. It is not shown on the page. Some inputs accept list as the id of a datalist within the page. This will change the widget, giving easy access at preferred values. type='text' as autocomplete, type='color' as dialog palette, type='range' as ticks.
id
The element acting a heading for the details container, optional, strongly recommended. When not open, the only displayed prose of its parent.
open
detail
output
Displayed inline, used to contain the value resulting from a calculation or outcomes of a user action. It is not submitted with the form, nevertheless it may specify a name. for can contain a space-separated list of id of elements involved in the computation. form can contain the id of the associated form, which can be anywhere in the current document. When unspecified, within an ancestor form, then the ancestor fills this role by default.
name
for
meter
Specific attributes are min, max, low, high, optimum, value. The meter indicates values that are under low, above high, usually with the color scheme.
low
high
optimum
Decrease Value: Increase
progress
Accepts max, value. but unlike meter, its minimum cannot be specified, implicitely being zero.
Dialog can be shown normally, or as modal. It is connected to forms, as forms can target dialogs for submission. A simple close button is implemented with onclick='parentNode.close()'. Opening a dialog when the hash fragment equals its id can be done in CSS. The close button then can be onclick='window.location.hash=""' or an anchor navigating to href='#'.
onclick='parentNode.close()'
onclick='window.location.hash=""'
href='#'
dialog:target { transition: 100ms; display: block; z-index: 50; }