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 812303 of <form>

  • Revision slug: Web/HTML/Element/form
  • Revision title: <form>
  • Revision id: 812303
  • Created:
  • Creator: wbamberg
  • Is current revision? No
  • Comment

Revision Content

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.

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 (username and password) fields and, if they agree, from autofilling 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 {{anch("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

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

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

10

 

Revision Source

<h2 id="Summary" name="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>

<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, palpable content</li>
 <li><dfn>Permitted content</dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, but not containing&nbsp;<code>&lt;form&gt;</code> elements</li>
 <li><dfn>Tag omission</dfn> {{no_tag_omission}}</li>
 <li><dfn>Permitted parent elements</dfn> Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">flow content</a></li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLFormElement")}}</li>
</ul>

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

<p><span style="line-height:21px">This element includes the&nbsp;</span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">global attributes</a><span style="line-height:21px">.</span></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<span class="st"> {{htmlattrxref("accept", "input")}}</span> 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 "UNKNOWN", 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 (username and password) fields and, if they agree, from autofilling 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 {{anch("Google Chrome notes")}}.</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" title="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/HTTP" title="https://www.w3.org/Protocols/rfc2616/rfc2616.html">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" title="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" title="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>

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

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

<h2 id="Specifications" name="Specifications"><label for="GET-name" label="">Specifications</label></h2>

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

<h2 id="Browser_compatibility" name="Browser_compatibility"><label for="GET-name" label="">Browser compatibility</label></h2>

<p><label for="GET-name" label="">{{CompatibilityTable}}</label></p>

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

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

<h3 id="Google_Chrome_notes"><label for="GET-name" label="">Google Chrome notes</label></h3>

<p><label for="GET-name" label="">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 <strong>not</strong> 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.</label></p>

<h2 id="See_also" name="See_also"><label for="GET-name" label="">See also</label></h2>

<ul>
 <li><label for="GET-name" label=""><a href="/en-US/docs/Web/Guide/HTML/Forms" title="/en-US/docs/Web/Guide/HTML/Forms">HTML forms guide</a></label></li>
 <li><label for="GET-name" label="">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")}}.</label></li>
</ul>

<p><label for="GET-name" label="">{{HTMLRef}}</label></p>

<p>&nbsp;</p>
Revert to this revision