Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1100899 of <form>

  • Revision slug: Web/HTML/Element/form
  • Revision title: <form>
  • Revision id: 1100899
  • Created:
  • Creator: Hugues-Antoine
  • Is current revision? Yes
  • Comment

Revision Content

{{HTMLRef}}

Summary

The HTML <form> element represents a document section that contains interactive controls to submit information to a web server.

It is possible to use the {{cssxref(':valid')}} and {{cssxref(':invalid')}} CSS pseudo-classes to style a <form> element.

Content categories Flow content, palpable content
Permitted content Flow content, but not containing <form> elements
Tag omission {{no_tag_omission}}
Permitted parent elements Any element that accepts flow content
DOM interface {{domxref("HTMLFormElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("accept")}} {{HTMLVersionInline(4)}} {{obsolete_inline}}
A comma-separated list of content types that the server accepts.
Usage note: This attribute has been removed in HTML5 and should no longer be used. Instead, use the {{htmlattrxref("accept", "input")}} attribute of the specific {{HTMLElement("input")}} element.
{{htmlattrdef("accept-charset")}}
A space- or comma-delimited list of character encodings that the server accepts. The browser uses them in the order in which they are listed. The default value, the reserved string "UNKNOWN", indicates the same encoding as that of the document containing the form element.
In previous versions of HTML, the different character encodings could be delimited by spaces or commas. In HTML5, only spaces are allowed as delimiters.
{{htmlattrdef("action")}}
The URI of a program that processes the form information. This value can be overridden by a {{htmlattrxref("formaction", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.
{{htmlattrdef("autocapitalize")}} {{non-standard_inline}}
This is a nonstandard attribute used by iOS Safari Mobile which controls whether and how the text value for textual form control descendants should be automatically capitalized as it is entered/edited by the user. If the autocapitalize attribute is specified on an individual form control descendant, it trumps the form-wide autocapitalize setting. The non-deprecated values are available in iOS 5 and later. The default value is sentences. Possible values are:
  • none: Completely disables automatic capitalization
  • sentences: Automatically capitalize the first letter of sentences.
  • words: Automatically capitalize the first letter of words.
  • characters: Automatically capitalize all characters.
  • on: {{deprecated_inline}} Deprecated since iOS 5.
  • off: {{deprecated_inline}} Deprecated since iOS 5.
{{htmlattrdef("autocomplete")}} {{HTMLVersionInline(5)}}
Indicates whether input elements can by default have their values automatically completed by the browser. This setting can be overridden by an autocomplete attribute on an element belonging to the form. Possible values are:
  • off: The user must explicitly enter a value into each field for every use, or the document provides its own auto-completion method; the browser does not automatically complete entries.
  • on: The browser can automatically complete values based on values that the user has previously entered in the form.
For most modern browsers (including Firefox 38+, Google Chrome 34+, IE 11+) setting the autocomplete attribute will not prevent a browser's password manager from asking the user if they want to store login fields (username and password), if the user permits the storage the browser will autofill the login the next time the user visits the page. See The autocomplete attribute and login fields.

Note: If you set autocomplete to off in a form because the document provides its own auto-completion, then you should also set autocomplete to off for each of the form's input elements that the document can auto-complete. For details, see Google Chrome notes.

{{htmlattrdef("enctype")}}
When the value of the method attribute is post, enctype is the MIME type of content that is used to submit the form to the server. Possible values are:
  • application/x-www-form-urlencoded: The default value if the attribute is not specified.
  • multipart/form-data: The value used for an {{HTMLElement("input")}} element with the type attribute set to "file".
  • text/plain (HTML5)

This value can be overridden by a {{htmlattrxref("formenctype", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.

{{htmlattrdef("method")}}
The HTTP method that the browser uses to submit the form. Possible values are:
  • post: Corresponds to the HTTP POST method ; form data are included in the body of the form and sent to the server.
  • get: Corresponds to the HTTP GET method; form data are appended to the action attribute URI with a '?' as separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.

This value can be overridden by a {{htmlattrxref("formmethod", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.

{{htmlattrdef("name")}}
The name of the form. In HTML 4, its use is deprecated (id should be used instead). It must be unique among the forms in a document and not just an empty string in HTML 5.
{{htmlattrdef("novalidate")}} {{HTMLVersionInline(5)}}
This Boolean attribute indicates that the form is not to be validated when submitted. If this attribute is not specified (and therefore the form is validated), this default setting can be overridden by a {{htmlattrxref("formnovalidate", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element belonging to the form.
{{htmlattrdef("target")}}
A name or keyword indicating where to display the response that is received after submitting the form. In HTML 4, this is the name/keyword for a frame. In HTML5, it is a name/keyword for a browsing context (for example, tab, window, or inline frame). The following keywords have special meanings:
  • _self: Load the response into the same HTML 4 frame (or HTML5 browsing context) as the current one. This value is the default if the attribute is not specified.
  • _blank: Load the response into a new unnamed HTML 4 window or HTML5 browsing context.
  • _parent: Load the response into the HTML 4 frameset parent of the current frame, or HTML5 parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.
  • _top: HTML 4: Load the response into the full original window, and cancel all other frames. HTML5: Load the response into the top-level browsing context (i.e., the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.
  • iframename: The response is displayed in a named {{HTMLElement("iframe")}}.

HTML5: This value can be overridden by a {{htmlattrxref("formtarget", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.

Examples

HTML Content

<!-- Simple form which will send a GET request -->
<form action="">
  <label for="GET-name">Name:</label>
  <input id="GET-name" type="text">
  <input type="submit" value="Save">
</form>

<!-- Simple form which will send a POST request -->
<form action="" method="post">
  <label for="POST-name">Name:</label>
  <input id="POST-name" type="text">
  <input type="submit" value="Save">
</form>

<!-- Form with fieldset, legend, and label -->
<form action="" method="post">
  <fieldset>
    <legend>Title</legend>
    <input type="radio" id="radio"> <label for="radio">Click me</label>
  </fieldset>
</form>

{{ EmbedLiveSample('Examples', '100%', 110) }}

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'forms.html#the-form-element', '<form>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'forms.html#the-form-element', '<form>')}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'interact/forms.html#h-17.3', '<form>')}} {{Spec2('HTML4.01')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0[1] {{CompatGeckoDesktop("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
novalidate attribute 1.0 {{CompatGeckoDesktop("2.0")}} 10 {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
novalidate attribute {{CompatUnknown}} {{CompatGeckoMobile("2.0")}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] The Google Chrome UI for auto-complete request varies, depending on whether autocomplete is set to off on input elements as well as their form. Specifically, when a form has autocomplete set to off and its input element's autocomplete field is not set, then if the user asks for autofill suggestions for the input element, Chrome might display a message saying "autocomplete has been disabled for this form." On the other hand, if both the form and the input element have autocomplete set to off, the browser will not display that message. For this reason, you should set autocomplete to off for each input that has custom auto-completion.

See also

  • HTML forms guide
  • Other elements that are used for creating forms: {{HTMLElement("button")}}, {{HTMLElement("datalist")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}},{{HTMLElement("keygen")}}, {{HTMLElement("label")}}, {{HTMLElement("legend")}}, {{HTMLElement("meter")}}, {{HTMLElement("optgroup")}}, {{HTMLElement("option")}}, {{HTMLElement("output")}}, {{HTMLElement("progress")}}, {{HTMLElement("select")}}, {{HTMLElement("textarea")}}.

Revision Source

<div>{{HTMLRef}}</div>

<h2 id="Summary">Summary</h2>

<p>The <strong>HTML <code>&lt;form&gt;</code> element</strong> represents a document section that contains interactive controls to submit information to a web server.</p>

<p>It is possible to use the {{cssxref(':valid')}} and {{cssxref(':invalid')}} CSS pseudo-classes to style a <code>&lt;form&gt;</code> element.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/HTML/Content_categories#Flow_content">Flow content</a>, palpable content</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td><a href="/en-US/docs/HTML/Content_categories#Flow_content">Flow content</a>, but not containing <code>&lt;form&gt;</code> elements</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Flow_content">flow content</a></td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLFormElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="/en-US/docs/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("accept")}} {{HTMLVersionInline(4)}} {{obsolete_inline}}</dt>
 <dd>A comma-separated list of content types that the server accepts.
 <div class="note"><strong>Usage note:</strong> This attribute has been removed in HTML5 and should no longer be used. Instead, use the {{htmlattrxref("accept", "input")}} attribute of the specific {{HTMLElement("input")}} element.</div>
 </dd>
 <dt>{{htmlattrdef("accept-charset")}}</dt>
 <dd>A space- or comma-delimited list of character encodings that the server accepts. The browser uses them in the order in which they are listed. The default value, the reserved string <code>"UNKNOWN"</code>, indicates the same encoding as that of the document containing the form element.<br />
 In previous versions of HTML, the different character encodings could be delimited by spaces or commas. In HTML5, only spaces are allowed as delimiters.</dd>
 <dt>{{htmlattrdef("action")}}</dt>
 <dd>The URI of a program that processes the form information. This value can be overridden by a {{htmlattrxref("formaction", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.</dd>
 <dt>{{htmlattrdef("autocapitalize")}} {{non-standard_inline}}</dt>
 <dd>This is a nonstandard attribute used by iOS Safari Mobile which controls whether and how the text value for textual form control descendants should be automatically capitalized as it is entered/edited by the user. If the <code>autocapitalize</code> attribute is specified on an individual form control descendant, it trumps the form-wide <code>autocapitalize</code> setting. The non-deprecated values are available in iOS 5 and later. The default value is <code>sentences</code>. Possible values are:
 <ul>
  <li><code>none</code>: Completely disables automatic capitalization</li>
  <li><code>sentences</code>: Automatically capitalize the first letter of sentences.</li>
  <li><code>words</code>: Automatically capitalize the first letter of words.</li>
  <li><code>characters</code>: Automatically capitalize all characters.</li>
  <li><code>on</code>: {{deprecated_inline}} Deprecated since iOS 5.</li>
  <li><code>off</code>: {{deprecated_inline}} Deprecated since iOS 5.</li>
 </ul>
 </dd>
 <dt>{{htmlattrdef("autocomplete")}} {{HTMLVersionInline(5)}}</dt>
 <dd>Indicates whether input elements can by default have their values automatically completed by the browser. This setting can be overridden by an <code>autocomplete</code> attribute on an element belonging to the form. Possible values are:
 <ul>
  <li><code>off</code>: The user must explicitly enter a value into each field for every use, or the document provides its own auto-completion method; the browser does not automatically complete entries.</li>
  <li><code>on</code>: The browser can automatically complete values based on values that the user has previously entered in the form.</li>
 </ul>
 For most modern browsers (including Firefox 38+, Google Chrome 34+, IE 11+) setting the autocomplete attribute will not prevent a browser's password manager from asking the user if they want to store login fields (username and password), if the user permits the storage the browser will autofill the login the next time the user visits the page. See <a href="/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#The_autocomplete_attribute_and_login_fields">The autocomplete attribute and login fields</a>.</dd>
 <dd>
 <div class="note">
 <p><strong>Note: </strong>If you set <code>autocomplete</code> to <code>off</code> in a form because the document provides its own auto-completion, then you should also set <code>autocomplete</code> to <code>off</code> for each of the form's <code>input</code> elements that the document can auto-complete. For details, see <a href="#Google_Chrome_notes">Google Chrome notes</a>.</p>
 </div>
 </dd>
 <dt>{{htmlattrdef("enctype")}}</dt>
 <dd>When the value of the <code>method</code> attribute is <code>post</code>, enctype is the <a href="https://en.wikipedia.org/wiki/Mime_type">MIME type</a> of content that is used to submit the form to the server. Possible values are:
 <ul>
  <li><code>application/x-www-form-urlencoded</code>: The default value if the attribute is not specified.</li>
  <li><code>multipart/form-data</code>: The value used for an {{HTMLElement("input")}} element with the <code>type</code> attribute set to "file".</li>
  <li><code>text/plain (HTML5)</code></li>
 </ul>

 <p>This value can be overridden by a {{htmlattrxref("formenctype", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.</p>
 </dd>
 <dt>{{htmlattrdef("method")}}</dt>
 <dd>The <a href="/en-US/docs/Web/HTTP">HTTP</a> method that the browser uses to submit the form. Possible values are:
 <ul>
  <li><code>post</code>: Corresponds to the HTTP <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5">POST method</a> ; form data are included in the body of the form and sent to the server.</li>
  <li><code>get</code>: Corresponds to the HTTP <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">GET method</a>; form data are appended to the <code>action</code> attribute URI with a '?' as separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.</li>
 </ul>

 <p>This value can be overridden by a {{htmlattrxref("formmethod", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.</p>
 </dd>
 <dt>{{htmlattrdef("name")}}</dt>
 <dd>The name of the form. In HTML 4, its use is deprecated (<code>id</code> should be used instead). It must be unique among the forms in a document and not just an empty string in HTML 5.</dd>
 <dt>{{htmlattrdef("novalidate")}} {{HTMLVersionInline(5)}}</dt>
 <dd>This Boolean attribute indicates that the form is not to be validated when submitted. If this attribute is not specified (and therefore the form is validated), this default setting can be overridden by a {{htmlattrxref("formnovalidate", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element belonging to the form.</dd>
 <dt>{{htmlattrdef("target")}}</dt>
 <dd>A name or keyword indicating where to display the response that is received after submitting the form. In HTML 4, this is the name/keyword for a frame. In HTML5, it is a name/keyword for a <em>browsing context</em> (for example, tab, window, or inline frame). The following keywords have special meanings:
 <ul>
  <li><code>_self</code>: Load the response into the same HTML 4 frame (or HTML5 browsing context) as the current one. This value is the default if the attribute is not specified.</li>
  <li><code>_blank</code>: Load the response into a new unnamed HTML 4 window or HTML5 browsing context.</li>
  <li><code>_parent</code>: Load the response into the HTML 4 frameset parent of the current frame, or HTML5 parent browsing context of the current one. If there is no parent, this option behaves the same way as <code>_self</code>.</li>
  <li><code>_top</code>: HTML 4: Load the response into the full original window, and cancel all other frames. HTML5: Load the response into the top-level browsing context (i.e., the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as <code>_self</code>.</li>
  <li><em>iframename</em>: The response is displayed in a named {{HTMLElement("iframe")}}.</li>
 </ul>

 <p>HTML5: This value can be overridden by a {{htmlattrxref("formtarget", "button")}} attribute on a {{HTMLElement("button")}} or {{HTMLElement("input")}} element.</p>
 </dd>
</dl>

<h2 id="Examples" name="Examples">Examples</h2>

<h3 id="HTML_Content">HTML Content</h3>

<pre class="brush: html">
&lt;!-- Simple form which will send a GET request --&gt;
&lt;form action=""&gt;
&nbsp; &lt;label for="GET-name"&gt;Name:&lt;/label&gt;
&nbsp; &lt;input id="GET-name" type="text"&gt;
&nbsp; &lt;input type="submit" value="Save"&gt;
&lt;/form&gt;

&lt;!-- Simple form which will send a POST request --&gt;
&lt;form action="" method="post"&gt;
&nbsp; &lt;label for="POST-name"&gt;Name:&lt;/label&gt;
&nbsp; &lt;input id="POST-name" type="text"&gt;
&nbsp; &lt;input type="submit" value="Save"&gt;
&lt;/form&gt;

&lt;!-- Form with fieldset, legend, and label --&gt;
&lt;form action="" method="post"&gt;
&nbsp; &lt;fieldset&gt;
&nbsp; &nbsp; &lt;legend&gt;Title&lt;/legend&gt;
&nbsp; &nbsp; &lt;input type="radio" id="radio"&gt; &lt;label for="radio"&gt;Click me&lt;/label&gt;
&nbsp; &lt;/fieldset&gt;
&lt;/form&gt;
</pre>

<p>{{ EmbedLiveSample('Examples', '100%', 110) }}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'forms.html#the-form-element', '&lt;form&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'forms.html#the-form-element', '&lt;form&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'interact/forms.html#h-17.3', '&lt;form&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0<sup>[1]</sup></td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>novalidate</code> attribute</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>10</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>novalidate</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("2.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p><a id="Google_Chrome_notes" name="Google_Chrome_notes"></a>[1] The Google Chrome UI for auto-complete request varies, depending on whether <code>autocomplete</code> is set to <code>off</code> on <code>input</code> elements as well as their form. Specifically, when a form has <code>autocomplete</code> set to <code>off</code> and its input element's <code>autocomplete</code> field is not set, then if the user asks for autofill suggestions for the input element, Chrome might display a message saying "autocomplete has been disabled for this form." On the other hand, if both the form and the input element have <code>autocomplete</code> set to <code>off</code>, the browser will not display that message. For this reason, you should set <code>autocomplete</code> to <code>off</code> for each input that has custom auto-completion.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/Guide/HTML/Forms">HTML forms guide</a></li>
 <li>Other elements that are used for creating forms: {{HTMLElement("button")}}, {{HTMLElement("datalist")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}},{{HTMLElement("keygen")}}, {{HTMLElement("label")}}, {{HTMLElement("legend")}}, {{HTMLElement("meter")}}, {{HTMLElement("optgroup")}}, {{HTMLElement("option")}}, {{HTMLElement("output")}}, {{HTMLElement("progress")}}, {{HTMLElement("select")}}, {{HTMLElement("textarea")}}.</li>
</ul>
Revert to this revision