HTML - <form> Tag


Advertisements


Description

The HTML <form> tag is used for creating a form for user input. A form can contain textfields, checkboxes, radio-buttons and more. Forms are used to pass user-data to a specified URL.

Example

Live Demo
<!DOCTYPE html>
<html>

   <head>
      <title>HTML form Tag</title>
   </head>

   <body>
      <form action = "/cgi-bin/hello_get.cgi" method = "get">
         First name: 
            <input type = "text" name = "first_name" value = "" maxlength = "100" />
         <br />
         
         Last name: 
            <input type = "text" name = "last_name" value = "" maxlength = "100" />
         <input type = "submit" value ="Submit" />
      </form>
   </body>

</html>

This will produce the following result −

Global Attributes

This tag supports all the global attributes described in HTML Attribute Reference

Specific Attributes

The HTML <form> tag also supports the following additional attributes −

Attribute Value Description
accept MIME_type Specifies a comma-separated list of content types that the server accepts.
accept-charset charset list Specifies a list of character encodings that the server accepts. The default value is "unknown".
action URL Specifies a URI/URL of the back-end script that will process the form
autocompletehtml-5 on
off
Specifies whether form should have autocomplete on or off
enctype mimetypes The mime type used to encode the content of the form.
method get
post
Specifies the HTTP method to use when the form is submitted. Possible values −
  • get (the form data is appended to the URL when submitted)
  • post (the form data is not appended to the URL)
name form name Defines a unique name for the form.
novalidate html-5 novalidate Specifies that the form should not be validated when submitted.
target _blank
_self
_parent
_top

Target to open the given URL.

_blank − the target URL will open in a new window.

_self − the target URL will open in the same frame as it was clicked.

_parent − the target URL will open in the parent frameset.

_top − the target URL will open in the full body of the window.

Event Attributes

This tag supports all the event attributes described in HTML Events Reference

Browser Support

Chrome Firefox IE Opera Safari Android
Yes Yes Yes Yes Yes Yes

html_tags_reference.htm

Advertisements