CKTIS / HTML
form attribute — explicit form association
The form attribute identifies a control's form owner, even when the control is outside that form. Its value is the form's id in the same tree, not its name or a CSS selector.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
form="form-id"The form="form-id" attribute explicitly identifies an element's form owner. Its value must match the id of a form element in the same tree; do not add #. Association does not move the element in the DOM and lets a control sit outside its form.
The attribute is supported by button, fieldset, input, object, output, select, textarea, and form-associated custom elements. It is not a global attribute. Association alone does not mean an element contributes a value when the form is submitted: for example, fieldset and output do not.
Without this attribute, the owner is normally the nearest ancestor form. When the form owner is reset, the ID specified by the attribute is looked up only if the element is connected to a document. In that case, if the lookup does not identify a form, the element has no owner rather than falling back to its ancestor form. An empty value does not restore default association in this case — remove the attribute instead. In a detached subtree, the element can still associate with its nearest ancestor form even if the attribute does not identify a form. Use unique IDs.
The attribute is not inherited: setting form on a fieldset does not automatically assign its controls to the specified form. Built-in elements supporting this attribute expose a .form property returning the form or null. In the example, the external input belongs to order, appears in order.elements, and contributes its value to FormData(order).
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Explicit form association</title>
<form id="order"></form>
<label>Item <input id="item" name="item" value="book" form="order"></label>
<pre id="result"></pre>
<script>
const order = document.getElementById('order');
const item = document.getElementById('item');
document.getElementById('result').textContent = [
item.form === order,
order.elements.namedItem('item') === item,
new FormData(order).get('item')
].join('\n');
</script>
</html>Result
true true book
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.