Forms & Controls

HTML <form> element

Build a form with the HTML form generator

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

NameTypeDescription
accept-charsetUTF-8Specifies the character encoding for form submission. Modern conforming HTML uses UTF-8; normally omit this because UTF-8 is the expected encoding.
actionURLSets 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.
autocompleteordered autofill tokens or on/offGives 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.
enctypeenumerated: application/x-www-form-urlencoded, multipart/form-data, text/plainControls 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.
methodenumerated: get, post, dialogSets 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.
namestringProvides 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.
novalidatebooleanDisables native constraint validation for form submission. It does not make invalid data safe; validate the same constraints on the server.
relspace-separated relationship keywordsDefines relationships between a document and a linked resource or navigation target. Valid tokens depend on the element; stylesheet, noopener and canonical have different purposes.
targetbrowsing context name or reserved keywordSelects 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
HTML Reference