Posts in current category

HTML5 <form> tag


May 03, 2021 14:00 HTML5


Table of contents


Instance

HTML form with two input fields and a submit button:

<form action="demo_form.php" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="提交">
</form>
Try it out . . .

Browser support

HTML5 <form> tag HTML5 <form> tag HTML5 <form> tag HTML5 <form> tag HTML5 <form> tag

All major browsers support the label.


Label definition and instructions for use

The label is used to create HTML forms for user input.

You can specify a style for an element using the :valid and :invalid CSS pseudo-classes.


The element contains one or more of the following form elements:


The difference between HTML 4.01 and HTML5

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


The difference between HTML and XHTML

In XHTML, the name property has been discarded. Use the global id property instead.


Property

New: The new property in HTML5.

Property Value Describe
accept MIME_type HTML5 is not supported. /b10>Specifies the type of file that the server receives. (Files are submitted via file upload)
accept-charset character_set Specifies the set of form data characters that the server can process.
action Url Specify where form data is sent when a form is submitted.
autocomplete New on
off
Specify whether to enable the form's auto-completion feature.
enctype application/x-www-form-urlencoded
multipart/form-data
text/plain
Specify how form data is encoded before it is sent to the server. (For the case of method-"post")
method get
post
Specifies the HTTP method used to send form data.
name text Specify the name of the form.
novalidate New novalidate If you use this property, the form is not validated when it is submitted.
target _blank
_self
_parent
_top
Specify where to open the action URL.


Global properties

Labels support the global properties of HTML.


The event property

The tag supports the event properties of HTML.


HTML5 <form> tag

Try it - instance

A form with a check box
This form contains two check boxes and a submit button.

A form with a turntable button
This form contains two check boxes and a submit button.


Related articles

HTML tutorial: HTML forms and inputs

HTML DOM Reference Manual: Form Object