Latest web development tutorials

HTML <form> tag

Examples

With two input fields and a submit button HTML form:

<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"
(For more examples, see the bottom of the page)

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the <form> tag.


Tag definitions and instructions

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

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


Differences between HTML 4.01 and HTML5

HTML5 adds two new attributes: autocomplete and novalidate, while some HTML 4.01 attributes are no longer supported.


Differences between HTML and XHTML

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


Attributes

New: HTML5 new property.

属性 描述
accept MIME_type HTML5 不支持。规定服务器接收到的文件的类型。(文件是通过文件上传提交的)
accept-charset character_set 规定服务器可处理的表单数据字符集。
action URL 规定当提交表单时向何处发送表单数据。
autocomplete New on
off
规定是否启用表单的自动完成功能。
enctype application/x-www-form-urlencoded
multipart/form-data
text/plain
规定在向服务器发送表单数据之前如何对其进行编码。(适用于 method="post" 的情况)
method get
post
规定用于发送表单数据的 HTTP 方法。
name text 规定表单的名称。
novalidate New novalidate 如果使用该属性,则提交表单时不进行验证。
target _blank
_self
_parent
_top
规定在何处打开 action URL。


Global Properties

<form> tag supports HTML global properties .


Event Properties

<form> tag supports HTML event properties .


Examples

Try - Example

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

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


related articles

HTML Tutorial: HTML Forms and Input

HTML DOM Reference: Form1 objects