`<form>` HTML form element
The <form> HTML element represents a document section containing interactive controls for submitting information.
The <form> HTML element represents a document section containing interactive controls for submitting information.
It is possible to use the :valid and :invalid CSS pseudo-classes to style a <form> element based on whether the elements inside the form are valid.
tabbed-standard
```html interactive-example
```js interactive-example
document.querySelector("form").addEventListener("submit", (event) => {
event.preventDefault();
});
```css interactive-example form.form-example { display: table; }
div.form-example { display: table-row; }
label, input { display: table-cell; margin-bottom: 10px; }
label { padding-right: 10px; }
## Attributes
This element includes the [global attributes](/docs/Web/HTML/Reference/Global_attributes).
- `accept`
- : Comma-separated [content types](/docs/Web/SVG/Guides/Content_type) the server accepts.
> [!NOTE]
> **This attribute has been deprecated and should not be used.** Instead, use the [`accept`](/docs/Web/HTML/Reference/Elements/input#accept) attribute on `<input type=file>` elements.
- `accept-charset`
- : The character encoding accepted by the server.
The specification allows a single case-insensitive value of `"UTF-8"`, reflecting the ubiquity of this encoding (historically multiple character encodings could be specified as a comma-separated or space-separated list).
- `autocapitalize`
- : Controls whether inputted text is automatically capitalized and, if so, in what manner. See the [`autocapitalize`](/docs/Web/HTML/Reference/Global_attributes/autocapitalize) global attribute page for more information.
- [`autocomplete`](/docs/Web/HTML/Reference/Attributes/autocomplete)
- : Indicates whether input elements can by default have their values automatically completed by the browser. `autocomplete` attributes on form elements override it on `<form>`. Possible values:
- `off`: The browser may not automatically complete entries. (Browsers tend to ignore this for suspected login forms; see [Managing autofill for login fields](/docs/Web/Security/Practical_implementation_guides/Turning_off_form_autocompletion#managing_autofill_for_login_fields).)
- `on`: The browser may automatically complete entries.
- `name`
- : The name of the form. The value must not be the empty string, and must be unique among the `form` elements in the forms collection that it is in, if any. The name becomes a property of the Window, Document, and document.forms objects, containing a reference to the form element.
- [`rel`](/docs/Web/HTML/Reference/Attributes/rel)
- : Controls the annotations and what kinds of links the form creates. Annotations include [`external`](/docs/Web/HTML/Reference/Attributes/rel#external), [`nofollow`](/docs/Web/HTML/Reference/Attributes/rel#nofollow), [`opener`](/docs/Web/HTML/Reference/Attributes/rel#opener), [`noopener`](/docs/Web/HTML/Reference/Attributes/rel#noopener), and [`noreferrer`](/docs/Web/HTML/Reference/Attributes/rel#noreferrer). Link types include [`help`](/docs/Web/HTML/Reference/Attributes/rel#help), [`prev`](/docs/Web/HTML/Reference/Attributes/rel#prev), [`next`](/docs/Web/HTML/Reference/Attributes/rel#next), [`search`](/docs/Web/HTML/Reference/Attributes/rel#search), and [`license`](/docs/Web/HTML/Reference/Attributes/rel#license). The [`rel`](/docs/Web/HTML/Reference/Attributes/rel) value is a space-separated list of these enumerated values.
### Attributes for form submission
The following attributes control behavior during form submission.
- `action`
- : The URL that processes the form submission. This value can be overridden by a [`formaction`](/docs/Web/HTML/Reference/Elements/button#formaction) attribute on a button, [`<input type="submit">`](/docs/Web/HTML/Reference/Elements/input/submit), or [`<input type="image">`](/docs/Web/HTML/Reference/Elements/input/image) element. This attribute is ignored when `method="dialog"` is set.
- `enctype`
- : If the value of the `method` attribute is `post`, `enctype` is the [MIME type](https://en.wikipedia.org/wiki/Mime_type) of the form submission. Possible values:
- `application/x-www-form-urlencoded`: The default value.
- `multipart/form-data`: Use this if the form contains input elements with `type=file`.
- `text/plain`: Useful for debugging purposes.
This value can be overridden by [`formenctype`](/docs/Web/HTML/Reference/Elements/button#formenctype) attributes on button, [`<input type="submit">`](/docs/Web/HTML/Reference/Elements/input/submit), or [`<input type="image">`](/docs/Web/HTML/Reference/Elements/input/image) elements.
- `method`
- : The [HTTP](/docs/Web/HTTP) method to submit the form with.
The only allowed methods/values are (case insensitive):
- `post`: The POST method; form data sent as the [request body](/docs/Web/API/Request/body).
- `get` (default): The GET; form data appended to the `action` URL with a `?` separator. Use this method when the form [has no side effects](/docs/Glossary/Idempotent).
- `dialog`: When the form is inside a dialog, closes the dialog and causes a `submit` event to be fired on submission, without submitting data or clearing the form.
This value is overridden by [`formmethod`](/docs/Web/HTML/Reference/Elements/button#formmethod) attributes on button, [`<input type="submit">`](/docs/Web/HTML/Reference/Elements/input/submit), or [`<input type="image">`](/docs/Web/HTML/Reference/Elements/input/image) elements.
- `novalidate`
- : This Boolean attribute indicates that the form shouldn't be validated when submitted. If this attribute is not set (and therefore the form **_is_** validated), it can be overridden by a [`formnovalidate`](/docs/Web/HTML/Reference/Elements/button#formnovalidate) attribute on a button, [`<input type="submit">`](/docs/Web/HTML/Reference/Elements/input/submit), or [`<input type="image">`](/docs/Web/HTML/Reference/Elements/input/image) element belonging to the form.
- `target`
- : Indicates where to display the response after submitting the form. It is a name/keyword for a _browsing context_ (for example, tab, window, or iframe). The following keywords have special meanings:
- `_self` (default): Load into the same browsing context as the current one.
- `_blank`: Load into a new unnamed browsing context. This provides the same behavior as setting [`rel="noopener"`](#rel) which does not set [`window.opener`](/docs/Web/API/Window/opener).
- `_parent`: Load into the parent browsing context of the current one. If no parent, behaves the same as `_self`.
- `_top`: Load into the top-level browsing context (i.e., the browsing context that is an ancestor of the current one and has no parent). If no parent, behaves the same as `_self`.
- `_unfencedTop`: Load the response from a form inside an embedded [fenced frame](/docs/Web/API/Fenced_frame_API) into the top-level frame (i.e., traversing beyond the root of the fenced frame, unlike other reserved destinations). Only available inside fenced frames.
This value can be overridden by a [`formtarget`](/docs/Web/HTML/Reference/Elements/button#formtarget) attribute on a button, [`<input type="submit">`](/docs/Web/HTML/Reference/Elements/input/submit), or [`<input type="image">`](/docs/Web/HTML/Reference/Elements/input/image) element.
## Examples
```html
<!-- Form which will send a GET request to the current URL -->
<form method="get">
<label>
Name:
<input name="submitted-name" autocomplete="name" />
</label>
<button>Save</button>
</form>
<!-- Form which will send a POST request to the current URL -->
<form method="post">
<label>
Name:
<input name="submitted-name" autocomplete="name" />
</label>
<button>Save</button>
</form>
<!-- Form with fieldset, legend, and label -->
<form method="post">
<fieldset>
<legend>Do you agree to the terms?</legend>
<label><input type="radio" name="radio" value="yes" /> Yes</label>
<label><input type="radio" name="radio" value="no" /> No</label>
</fieldset>
</form>
js hidden
document.querySelectorAll("form").forEach((form) => {
form.addEventListener("submit", (event) => {
event.preventDefault();
});
});
Result
Examples
Technical summary
| Content categories | Flow content, palpable content |
|---|---|
| Permitted content |
Flow content, but not containing <form> elements
|
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts flow content |
| Implicit ARIA role |
form
|
| Permitted ARIA roles |
search,
none
or presentation
|
| DOM interface | HTMLFormElement |
Specifications
Browser compatibility
See also
- HTML forms guide
- Other elements that are used when creating forms: button, datalist, fieldset, input, label, legend, meter, optgroup, option, output, progress, select, textarea.
- Getting a list of the elements in the form: HTMLFormElement.elements
- ARIA: Form role
- ARIA: Search role