Description

The HTML element <form> is used to define a form on an HTML document to accept user input, which can include any of the below input types.

The HTML form can contain one or more such input elements.

The below table summarizes its usage.

Usage Details
Placement It is displayed as a Block element.
Contents It can contain Block elements, Inline elements, and text.
It cannot include the <form> element.
Tags Both opening and closing tags are required.
Versions HTML 2, 3.2, 4, 4.01, 5

Syntax

Here is the basic syntax of the <form> element.

<form action="URL" method="http-method">...</form>

Examples

In the below example, the <form> element is used to define an HTML form.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML Element - form</title>
</head>
<body>
        <form action="http://www.example.com/" method="post">
        <fieldset>
            <legend>User Details</legend>
            <label for="name">Name:</label>
            <input type="text" id="name" name="name"><br><br>
            <label for="name">Email:</label>
            <input type="email" id="email" name="email"><br><br>
            <label for="male">Male</label>
            <input type="radio" name="gender" value="male" id="male">
            <label for="female">Female</label>            
            <input type="radio" name="gender" value="female" id="female">
        </fieldset>
    </form>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <form> tag.

Attribute Type Details
Element-Specific Attributes The tag <form> has some element-specific attributes listed in the below table.
Global Attributes Like all other HTML tags, the tag <form> supports the HTML Global Attributes.
Event Attributes The tag <form> also supports the HTML Event Attributes.

Here is a list of attributes that are specific to the <form> element.

Attribute Value Description
accept content-type-list Obsolete and not to be used.
A comma-separated list of content types that the server accepts on the URL specified.
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 (or) 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 (or) 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

Browser Compatibility

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

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

Related Links