References

Beginner-friendly references for web development, with live, editable examples.

The HTML form attribute

Attribute All modern browsers Updated
Quick answer

The HTML form attribute associates the control with a <form> elsewhere in the document by its id. It is used on most form controls (<input>, <button>, <select>, <textarea>, <output>, <fieldset>).

Overview

The form attribute associates the control with a <form> elsewhere in the document by its id. It applies to most form controls (<input>, <button>, <select>, <textarea>, <output>, <fieldset>).

It lets a control live outside its <form> in the DOM yet still submit with it.

Syntax

<form id="signup"> … </form>
<button form="signup">Join</button>

Values

Value
The id of a <form> element.

Best practices

  • Give every control a <label> so it has an accessible name.
  • Treat client-side constraints as a convenience — always validate again on the server, since they can be bypassed.
  • Choose the most specific input type so users get the right on-screen keyboard and built-in checks.
  • Keep the submitted name and value meaningful for whatever processes the form.

Frequently asked questions

What does the form attribute do?
Associates a control with a form by id.
Are HTML form attributes enough for validation?
They give instant feedback, but client-side checks can be bypassed, so always validate on the server too.
Do form controls still need a label?
Yes. Every control needs a <label> for an accessible name, whatever attributes you set.
Which elements use the form attribute?
It is an element-specific attribute, used on form controls such as <input>, <select> and <textarea>.