form
Associates a form control with a form element by ID, even when the control is outside the form's DOM tree. Enables complex layouts without nesting constraints.
Overview
The form attribute associates a form control with a <form> element by referencing the form's id. The control does not need to be a descendant of the form — it can be anywhere in the document. When the form is submitted, all associated controls (both nested and remote) are included in the form data.
This solves a real layout problem: sometimes the visual design requires form controls to be placed outside the form's DOM tree. Sticky footers, sidebar filters, dialog-based settings, and split-panel editors all benefit from this attribute.
Applies to: <input>, <select>, <textarea>, <button>, <output>, <fieldset>
Values
| Attribute | Value | Effect |
|---|---|---|
form="form-id" | The id of a <form> | Associates the control with that form |
(no form attribute) | — | Control belongs to its nearest ancestor <form> |
Basic Association
Place a control anywhere on the page and point it at a form with the form attribute. The value must exactly match the form's id.
Sticky Footer Buttons
A common layout: the form is in the content area and the submit/action buttons are in a sticky footer outside the form. The form attribute on the buttons connects them to the form.
The formaction and formmethod attributes work on remote buttons just as they do on nested buttons. See novalidate for the formnovalidate pattern.
Multiple Forms on One Page
When a page has multiple forms, the form attribute lets you assign shared controls to the correct form without nesting them.
Supported Elements
The form attribute works on every form-associated element.
Dialog Pattern
When advanced settings live inside a <dialog>, the fields are in a separate DOM subtree. The form attribute lets them contribute to the main form's submission data.
JavaScript API
The .form property on form controls returns the associated <form> element, whether the association is via nesting or the form attribute. FormData automatically includes remote controls.
Accessibility
- Screen readers associate controls with their form regardless of DOM position when the
formattribute is used. The accessibility tree respects the attribute. - Tab order follows DOM order, not form association. If a remote control is far from the form in the DOM, it may be reached much earlier or later during keyboard navigation. Place associated controls near the form when possible.
- Ensure remote controls are visually connected to their form through layout and proximity. Users should understand which form a control belongs to without inspecting the HTML.
Limitations
- The
formattribute value must be anid, not a selector. It must exactly match theidattribute of a<form>element on the page. - A control can only be associated with one form. If it has a
formattribute and is also nested inside a different<form>, theformattribute wins. - Constraint validation applies to remote controls just like nested ones. A remote
requiredfield will block submission if empty. - The
formattribute does not work across documents. The form and the control must be in the same document (not in different iframes). - Some older JavaScript form libraries may not account for remote controls. If you use
form.elementsornew FormData(form), remote controls are included — but manual DOM traversal (e.g.,form.querySelectorAll('input')) will miss them.
See Also
novalidate/formnovalidate— validation bypass on remote buttons<form>element reference<fieldset>— group controls (also supports theformattribute)<dialog>— modal dialogs where remote controls are useful