Code has been added to clipboard!

HTML form Tag

Reading time 2 min
Published Mar 19, 2019
Updated Sep 30, 2019

HTML form: Main Tips

  • The HTML <form> tag groups elements and sends their data to a web server.
  • A typical form element includes an <input> element with a type value of submit, which is used to submit an HTML <form>.

Use of form Element

The HTML <form> defines an area, containing interactive elements for submitting data.

Example
<form action="search" method="GET">
  Search Term: <input type="text" name="search_query">
  <input type="submit" value="Search">
</form>

Attributes to Use With form

accept

Sets a comma-separated list of types that a server accepts.

Example
<form action="upload" method="POST" enctype="multipart/form-data" accept="image/jpeg, image/png">
  Select Image: <input type="file" name="uploaded_filename">
  <input type="submit" value="Upload">
</form>

Note: removed in HTML5. Apply the accept attribute for a specific <input> element as an alternative.

accept-charset

Sets a space-separated list of character encodings used while submitting data.

Example
<form action="search" method="GET" accept-charset="ANSI ISO-8859-1">
  Search Term: <input type="text" name="search_query">
  <input type="submit" value="Search">
</form>

action

The URI of a program, processing the <form> data.

Example
<form action="http://www.bitdegree.org/" method="GET">
  Search Term: <input type="text" name="search_query">
  <input type="submit" value="Search">
</form>

autocomplete

Sets the autocomplete feature to ON or OFF.

Example
<form action="register" method="POST" autocomplete="on">
  Surname: <input type="text" name="name">
  Personal mail: <input type="text" name="email">
  <input type="submit" value="Register">
</form>

enctype

In cases when method attribute is post, enctype becomes the MIME type of data used for sending the form to the server.

Example
<form action="upload" method="POST" enctype="multipart/form-data" accept="image/*">
  Select Image: <input type="file" name="uploaded_filename">
  <input type="submit" value="Upload">
</form>

method

Sets the type of HTTP method for form submission.

Example
<form action="search" method="GET">
  Search Term: <input type="text" name="search_query">
  <input type="submit" value="Search">
</form>

name

Defines the <form> name.

Example
<form name="searchForm" action="search" method="GET">
  Search Term: <input type="text" name="search_query">
  <input type="submit" value="Search">
</form>

Note: HTML4 deprecated the name attribute. ID applies instead. In HTML5, the attribute cannot be empty and must be unique.

novalidate

Sets a form not to be validated during submission.

Example
<form action="register" method="POST" novalidate>
    Surname: <input type="text" name="name">
    Personal mail: <input type="text" name="email" required>
    <input type="submit" value="Register">
</form>

target

Sets the target location for the web server response.

Example
<form action="http://www.bitdegree.org/" method="GET" target="_blank">
  Search Term: <input type="text" name="search_query">
  <input type="submit" value="Search">
</form>

Browser support

Chrome
All
Edge
All
Firefox
All
IE
All
Opera
All
Safari
All

Mobile browser support

Chrome
All
Firefox
All
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>