HTML <form> tag

Updated: 09/12/2023 by Computer Hope
HTML form tag

The HTML (hypertext markup language) <form> tag is a block element used to create an interactive section on a web page allowing visitors to submit information to a web server. It is useful for gathering contact information, taking surveys, or allowing users to leave comments. The following sections contain information about this tag, including an example of it in use, and related attributes and browser compatibility.

Example of <form> code

<form action="script name" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" value="Submit">
</form>
Note

The "script name" in the action attribute should be changed to the name and location of your script file. For example, it could be changed to an ASP, Perl, PHP (PHP: Hypertext Preprocessor), or Python script file.

Example result

Name:
E-mail:

Note

The above example returns you to this page because nothing is used for the action. If you want a working example of the form tag, you can use our search engine found at the top and bottom of every page. For example, enter any computer term in the search to get an immediate definition of that term.

Attributes

All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <form> tag has the following unique attributes.

Attribute Description
accept-charset Designates the character encodings that are to be used when a form is submitted.
action Designates where to send form data. This attribute is either an ASP (Active Server Pages), JavaScript, Perl, PHP, or Python script.
autocomplete Toggles the autocomplete function.
enctype Designates how submitted form data should be encoded.
method Designates the HTTP (hypertext transfer protocol) method used for sending form data. The method is often either "get" or "post" as the value.
name Designates a name for the form.
novalidate Designates that the form should not be validated upon submission.
target Designates where the generated response is displayed upon submission.

Deprecated attributes

In addition to the above attributes, the <form> tag had the following deprecated attributes.

Attribute Description
accept Designates which file types a server accepts.

Compatibility

Edge Internet Explorer Firefox Safari Opera Chrome
All versions All versions All versions All version All versions All versions

Full list of form elements

Autocomplete, Browser, Compatibility, Container tag, Encode, File type, HTTP, URL, Visitor, Web design terms, Web page