Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/web/html/element/form/index.md
6532 views
---
title: '<form>: The Form element' slug: Web/HTML/Element/form page-type: html-element browser-compat: html.elements.form
---

{{HTMLSidebar}}

The <form> HTML element represents a document section containing interactive controls for submitting information.

{{EmbedInteractiveExample("pages/tabbed/form.html", "tabbed-standard")}}

It is possible to use the {{cssxref(':valid')}} and {{cssxref(':invalid')}} CSS pseudo-classes to style a <form> element based on whether the {{domxref("HTMLFormElement.elements", "elements")}} inside the form are valid.

Attributes

This element includes the global attributes.

  • accept {{deprecated_inline}}

    • : Comma-separated content types the server accepts.

      Note: This attribute has been deprecated and should not be used. Instead, use the {{htmlattrxref("accept", "input")}} attribute on <input type=file> elements.

  • accept-charset

    • : Space-separated {{Glossary("character encoding", "character encodings")}} the server accepts. The browser uses them in the order in which they are listed. The default value means the same encoding as the page. (In previous versions of HTML, character encodings could also be delimited by commas.)

  • autocapitalize {{non-standard_inline}}

    • : A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized. autocapitalize attributes on a form elements override it on <form>. Possible values:

      • none: No automatic capitalization.

      • sentences (default): Capitalize the first letter of each sentence.

      • words: Capitalize the first letter of each word.

      • characters: Capitalize all characters — that is, uppercase.

  • 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:

  • 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.

  • rel

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 {{htmlattrxref("formaction", "button")}} attribute on a {{HTMLElement("button")}}, <input type="submit">, or <input type="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 of the form submission. Possible values:

      • application/x-www-form-urlencoded: The default value.

      • multipart/form-data: Use this if the form contains {{HTMLElement("input")}} elements with type=file.

      • text/plain: Useful for debugging purposes.

      This value can be overridden by {{htmlattrxref("formenctype", "button")}} attributes on {{HTMLElement("button")}}, <input type="submit">, or <input type="image"> elements.

  • method

    • : The HTTP method to submit the form with. The only allowed methods/values are (case insensitive):

      • post: The {{HTTPMethod("POST")}} method; form data sent as the request body.

      • get (default): The {{HTTPMethod("GET")}}; form data appended to the action URL with a ? separator. Use this method when the form has no side effects.

      • dialog: When the form is inside a {{HTMLElement("dialog")}}, closes the dialog and throws a submit event on submission without submitting data or clearing the form.

      This value is overridden by {{htmlattrxref("formmethod", "button")}} attributes on {{HTMLElement("button")}}, <input type="submit">, or <input type="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 {{htmlattrxref("formnovalidate", "button")}} attribute on a {{HTMLElement("button")}}, <input type="submit">, or <input type="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" which does not set 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.

      This value can be overridden by a {{htmlattrxref("formtarget", "button")}} attribute on a {{HTMLElement("button")}}, <input type="submit">, or <input type="image"> element.

Examples

<!-- 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>

Technical summary

Content categories Flow content, palpable content
Permitted content Flow content, but not containing <form> elements
Tag omission {{no_tag_omission}}
Permitted parents Any element that accepts flow content
Implicit ARIA role form if the form has an accessible name, otherwise no corresponding role
Permitted ARIA roles search, none or presentation
DOM interface {{domxref("HTMLFormElement")}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • HTML forms guide

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

  • Getting a list of the elements in the form: {{domxref("HTMLFormElement.elements")}}

  • ARIA: Form role

  • ARIA: Search role