<form>


HTML <form> Tag

Instance

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<form action="demo-form.php">
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
<input type="submit" value="提交">
</form>

<p>点击"提交"按钮,表单数据将被发送到服务器上的“demo-form.php”。</p>

</body>
</html>

Run Example»

Click the "Run Instance" button to view the online instance


Browser support

1000.png

All major browsers support the <form> tag.


Tag definition and usage instructions

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

<form> element contains one or more of the following form elements:

  • <input>

  • ##< ;textarea>

  • <button>

  • <select>

  • ##<option> ;
  • <optgroup>
  • <fieldset>
  • <label>
Differences between HTML 4.01 and HTML5

HTML5 adds two new attributes: autocomplete and novalidate, and no longer supports HTML 4.01 certain properties.

Differences between HTML and XHTML

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

Attribute

New

: New attribute in HTML5.

AttributeacceptMIME_typeHTML5 is not supported. accept-charsetcharacter_setactionURLautocompleteNewoffenctype multipart/form-datamethod PostnametextnovalidateNewtarget _self

Global attributes

<form> tag supports HTML global attributes.


Event attributes

<form> tag supports HTML event attributes.


Examples

Try it out - Example

Form with checkboxes
This form contains two checkboxes and a submit button .

Instance

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<form action="demo-form.php" method="get">
  <input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
  <input type="checkbox" name="vehicle" value="Car" checked="checked"> I have a car<br>
  <input type="submit" value="提交">
</form>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance

Form with radio buttons
This form contains two radio buttons and a submit button.

Instance

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<form action="demo-form.php" method="get">
  <input type="radio" name="sex" value="Male"> Male<br>
  <input type="radio" name="sex" value="Female" checked="checked"> Female<br>
  <input type="submit" value="提交">
</form>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance


Related Articles

HTML Tutorial: HTML Forms and Input

HTML DOM Reference Manual: Form object


ValueDescription
Specifies the type of file received by the server. (Files are submitted via file upload)
Specifies the form data that the server can process character set.
Specifies where to send form data when the form is submitted.
on
Specifies whether to enable the autocomplete function of the form.
application/x-www-form-urlencoded text/plain

Specifies how to encode form data before sending it to the server. (Applicable to method="post")
get
Specifies the HTTP method used to send form data.
Specifies the name of the form.
novalidateIf this attribute is used, no validation will be performed when submitting the form.
_blank _parent
_top

specifies where to open the action URL.