HTML form Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The form attribute links a form-associated control to a <form> by matching that form’s id. It works on button, fieldset, input, object, output, select, and textarea.

By default, a control joins its nearest ancestor form. With form, you can place controls (or a submit button) outside the form markup — or override an ancestor form — and still include them in that form’s submission.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015.

Not inherited.

Setting form on a <fieldset> does not associate nested inputs. Each control needs its own form value or must live inside the target form.

HTML Syntax

syntax.html
<input form=" form_id">

form_id must equal the id of a <form> in the same document. Other values are ignored.

Attribute Values

One value: the form’s id. Common patterns:

PatternDescriptionTry it
Control outside formAn input / select / textarea placed outside <form> still submits with itTry it
External submit button<button type="submit" form="…"> submits the referenced formTry it
Override ancestorA control nested in one form can join a different form via formTry it

Live Preview

Point the external password field at Form A or Form B, then submit. Only the associated form includes that field.

The password input sits outside both forms. Apply a form id, then submit.

Two forms + external field

Form A

Form B

form="live-form-a"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Control Outside the Form

Associate a password field that is not nested in the form markup.

HTML
<form id="loginForm">
  <label for="username">Username:</label>
  <input type="text" id="username" name="username">
</form>

<label for="password">Password:</label>
<input form="loginForm" type="password" id="password" name="password">
Try It Yourself

How It Works

  1. Give the form an id. id="loginForm" is the association key.
  2. Set form on the control. form="loginForm" matches that id.
  3. Layout can differ. The field may sit anywhere in the document.
  4. On submit, the password is included with the form’s other fields.

Example 2 — Submit Button Outside the Form

Place the submit control in a toolbar or footer while still submitting the form.

HTML
<form id="signup">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required>
</form>

<button type="submit" form="signup">Create account</button>
Try It Yourself

How It Works

  1. Form keeps the fields. Email stays inside <form id="signup">.
  2. Button points at the form. form="signup" on a submit button.
  3. Click submits that form and runs its validation (e.g. required).
  4. Useful for layouts where the button cannot sit inside the form box.

Example 3 — Override the Ancestor Form

A control nested in one form can join a different form instead.

HTML
<form id="externalForm"></form>

<form id="internalForm">
  <label for="username">Username:</label>
  <input
    form="externalForm"
    type="text"
    name="username"
    id="username">
</form>
Try It Yourself

How It Works

  1. Nearest ancestor is ignored when form is set.
  2. Match another form’s id. Here form="externalForm".
  3. Submit externalForm to include the username; internalForm has no associated controls.
  4. Use sparingly — clear ids help you avoid confusing two forms.

Edge Cases & Pitfalls

Most mistakes come from wrong ids or assuming inheritance.

id

Value must match a form id

If no <form> has that id, the control is not associated with any form. Typos silently drop fields from submit.

inherit

Not inherited by children

form on <fieldset> (or a wrapper) does not attach nested inputs. Set form on each control you need.

submit

Association ≠ always submitted

Only submittable controls (named input, select, textarea, button) send values. output can be associated but is not submitted.

script

element.form is read-only

It returns the HTMLFormElement. To change ownership, use setAttribute("form", id) or remove the attribute.

vs

Not the same as <form>

This attribute lives on controls. The form element uses action, method, and related attributes instead.

Browser Support

form is an HTML attribute for form-associated elements in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

form

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support associating controls with a form by id.

97% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari 5.1+
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet Modern
Full support
Internet Explorer Limited / incomplete
Partial
form Widely supported

Bottom line: Safe to use in modern browsers for external controls and submit buttons. Avoid relying on it as the only path in very old IE.

Key Takeaways

  • Role: point a control at a <form> by matching that form’s id.
  • Elements: button, fieldset, input, object, output, select, textarea.
  • Override: form beats the nearest ancestor form when both apply.
  • Script: read element.form; write with setAttribute("form", id).

One line: form ties a control to a form by id — layout can stay flexible without losing submit behavior.

Frequently Asked Questions

It associates a form-associated control with a form element by matching that form’s id. The control then belongs to that form for submission and validation, even if it is not nested inside the form.
button, fieldset, input, object, output, select, and textarea. The form element itself does not use this attribute — it provides the id that controls reference.
The id of a form in the same document. Any other value is ignored. If no matching form exists, the control is not associated with a form.
Yes. A button with type=submit and form="formId" submits the referenced form, including its associated fields and constraint validation.
No. The attribute is not inherited. Each nested control needs its own form attribute or must sit inside the target form.
element.form returns the associated HTMLFormElement (read-only). To change the association, use setAttribute("form", "formId") or removeAttribute("form").

Next: formaction

Override a form’s action URL from a specific submit button.

formaction tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful