HTML Tags

HTML <form> Tag

Topic: HTML5 Tags ReferencePrev|Next

Description

The <form> tag defines an HTML form that contains interactive controls which enable a user to submit information to a web server. An HTML form is used to capture user information such as username, password, address details, credit card information, and so on.

Information can be captured in the form using many different form controls, such as <input>, <textarea>, <select>, <option>, <button>. There are also labeling and grouping controls, which include the <optgroup>, <fieldset>, <legend>, and <label> elements.

The following table summarizes the usages context and the version history of this tag.

Placement: Block
Content: Block, inline, and text, but not containing <form> elements
Start/End Tag: Start tag: required, End tag: required
Version: HTML 2, 3.2, 4, 4.01, 5

Syntax

The basic syntax of the <form> tag is given with:

HTML / XHTML: <form action="URL" method="get|post"> ... </form>

The example below shows the <form> tag in action.

<form action="action.php" method="post">
    <p>
        First name: <input type="text" name="first-name">
        <button type="submit" value="Submit">Submit</button>
        <button type="reset" value="Reset">Reset</button>
    </p>
</form>

Tag-Specific Attributes

The following table shows the attributes that are specific to the <form> tag.

Attribute Value Description
accept content-type-list Obsolete A comma-separated list of content types that the server accepts.
accept-charset charset-list Specifies the list of character encodings for input data that is accepted by the server processing this form.
action URL Specifies the URL of a program that processes the information submitted via the form.
autocomplete 
on
off
Specifies whether the browser autofill feature for a form is on or off.
enctype application/x-www-form-urlencoded
multipart/form-data
text/plain
Specifies how the form data should be encoded when submitting the form to the server (only for method="post")
method get
post
Specifies which HTTP method will be used to submit the form data.
name text Specifies the name of a form.
novalidate novalidate This Boolean attribute specifies that the form is not to be validated when submitted.
target _blank
_parent
_self
_top

framename
Specifies a target to display the response that is received after submitting the form

Note: The default value for the enctype attribute is application/x-www-form-urlencoded. The value multipart/form-data should be used in combination with the INPUT element (when type="file").


Global Attributes

Like all other HTML tags, the <form> tag supports the global attributes in HTML5.


Event Attributes

The <form> tag also supports the event attributes in HTML5.


Browser Compatibility

The <form> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 2+
  • Apple Safari 1+
  • Opera 4+

Further Reading

See tutorial on: HTML Forms.

Other form-related tags: <fieldset>, <legend>, <label>, <input>, <textarea>, <select>, <optgroup>, <option>, <button>.

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties