HTML <form> Tag.


An HTML form with two input fields and one submit button :

 <form action="demo_form.asp" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
Execute Code

Definition and Usage

The <form> tag is used to create an HTML form for user input.

The <form> element can contain one or more of the following form elements :

  • <input>
  • <textarea>
  • <button>
  • <select>
  • <option>
  • <optgroup>
  • <fieldset>
  • <label>

Browser Support

Element Chrome Internet Explorer Firefox Safari Opera
<form> Yes Yes Yes Yes Yes

Differences Between HTML 4.01 and HTML5

HTML5 has added two new attributes : autocomplete and novalidate, and removed the accept attribute.

Differences Between HTML and XHTML

In XHTML, the name attribute is deprecated. Use the global id attribute instead.


html5badge= New in HTML5.

Attribute Value Description
accept file_type Not supported in HTML5.
Specifies a comma-separated list of file types  that the server accepts (that can be submitted through the file upload)
accept-charset character_set Specifies the character encodings that are to be used for the form submission
action URL Specifies where to send the form-data when a form is submitted
autocomplete html5badgeon
Specifies whether a form should have autocomplete on or off
enctype application/x-www-form-urlencoded
Specifies how the form-data should be encoded when submitting it to the server (only for method="post")
method get
Specifies the HTTP method to use when sending form-data
name text Specifies the name of a form
novalidate html5badgenovalidate Specifies that the form should not be validated when submitted
target _blank
Specifies where to display the response that is received after submitting the form

Default CSS Settings

Most browsers will display the <form> element with the following default values :

form {
    display: block;
    margin-top: 0em;