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

AttributeValueEffect
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.