HTML: <form> tag
This HTML tutorial explains how to use the HTML element called the <form> tag with syntax and examples.
Description
The HTML <form> tag is used to create a form on a web page that has interactive controls for user input. This tag is also commonly referred to as the <form> element.
Syntax
In HTML, the syntax for the <form> tag is:
<body>
<form action="" method="get">
Company: <input type="text" name="company"><br>
Address: <input type="text" name="address"><br>
<input type="submit" value="Submit">
</form>
</body>
Sample Output
Attributes
In addition to the Global Attributes, the following is a list of attributes that are specific to the <form> tag:
Attribute | Description | HTML Compatibility |
---|---|---|
accept | List of content types (comma separated) that the server accepts as file types | HTML 4.01, Obsolete in HTML5 |
accept-charset | List of character sets (comma or space separated) that the server accepts | HTML 4.01, HTML5 |
action | URL of the page that processes the information submitted by the form | HTML 4.01, HTML5 |
autocomplete | Value of either on or off to indicate whether the browser can automatically complete the values in the input elements based on values previously entered in the form |
HTML5 |
enctype | When the method for the form is post , specifies the MIME type for how the form data should be encodedapplication/x-www-form-urlencoded (default) multipart/form-data text/plain |
HTML 4.01, HTML5 |
method | HTTP method used to submit the form. It can be either post or get |
HTML 4.01, HTML5 |
name | The name of the form | HTML 4.01, HTML5 |
novalidate | Boolean value indicating whether the form should be validated when it is submitted | HTML5 |
target | Specifies where to display the response after submitting the form. It can be one of the following values: _self, _blank, _parent, _top _self - means that the resource loads into the current frame or context _blank - means that the resource loads into a new window or context _parent - means that the resource loads into the parent frame or context _top - means that the resource loads into the full, original window |
HTML 4.01, HTML5 |
Note
- The HTML <form> element is found within the <body> tag.
- HTML forms can contain elements such as: <button>, <datalist>, <fieldset>, <input>, <keygen>, <label>, <legend>, <meter>, <optgroup>, <option>, <output>, <progress>, <select> and <textarea> tags
Browser Compatibility
The <form> tag has basic support with the following browsers:
- Chrome
- Android
- Firefox (Gecko)
- Firefox Mobile (Gecko)
- Internet Explorer (IE)
- Edge Mobile
- Opera
- Opera Mobile
- Safari (WebKit)
- Safari Mobile
Example
We will discuss the <form> tag below, exploring examples of how to use the <form> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.
Advertisements