Forms & Controls
HTML <form> element
Groups controls for submitting information. action identifies the destination and method controls the submission mode. Server-side validation remains necessary. A form groups controls and submits successful named values. GET is appropriate for safe retrieval; POST sends data in the request body but does not itself encrypt it. Use HTTPS, server-side validation and appropriate CSRF protection. Forms must not be nested. It accepts global HTML attributes; individual global features may be inapplicable or restricted.
Formal Syntax & Structure
html syntaxhtml
<form action="/search" method="get">Controls</form>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| accept-charset | UTF-8 | Specifies the character encoding for form submission. Modern conforming HTML uses UTF-8; normally omit this because UTF-8 is the expected encoding. |
| action | URL | Sets the destination for form submission. Omitting it submits to the current document URL; a submit button can override it with formaction. Use HTTPS for sensitive data. |
| autocomplete | ordered autofill tokens or on/off | Gives the browser the purpose of a form field or controls autofill. Use meaningful tokens such as email or current-password. A browser may still offer password-manager autofill even with off. |
| enctype | enumerated: application/x-www-form-urlencoded, multipart/form-data, text/plain | Controls form data encoding for POST submissions. Use multipart/form-data for file uploads. The default is application/x-www-form-urlencoded; text/plain is not robust for normal production use. |
| method | enumerated: get, post, dialog | Sets form submission behavior. GET encodes successful controls into the URL; POST sends data in the request body; dialog closes an associated dialog. GET is the default. HTTPS is required to protect transport. |
| name | string | Provides an element-specific name: a form field key, radio group name, named frame, metadata key, slot name or other defined purpose. Its meaning depends on the element; it is not a unique DOM identifier. |
| novalidate | boolean | Disables native constraint validation for form submission. It does not make invalid data safe; validate the same constraints on the server. |
| rel | space-separated relationship keywords | Defines relationships between a document and a linked resource or navigation target. Valid tokens depend on the element; stylesheet, noopener and canonical have different purposes. |
| target | browsing context name or reserved keyword | Selects where a link or form opens. _self uses the current context; _blank requests a new context. Use appropriate opener isolation when opening external pages. |
Return Value
HTMLFormElement
Content model: Flow content with no descendant form.
Working Example
Example Snippethtml
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>HTML example</title> </head> <body> <form action="/search" method="get"> <label> Query <input name="q"> </label> <button type="submit">Search</button> </form> </body></html>Browser Compatibility
Minimum supported versions across modern rendering engines
Widely Available
Blink (modern)
Chrome
1
Yes
EdgeHTML / Blink
Edge
12
Yes
Gecko
Firefox
1
Yes
WebKit
Safari
3
Yes
Basic form element; individual submission features and attributes have separate compatibility.
HTML Living Standard