HTML <form> element represents a document section containing interactive controls for submitting information.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

It is possible to use the :valid and :invalid CSS pseudo-classes to style a <form> element based on whether or not the 元素 inside the form are valid.

内容类别 流内容 , palpable content
准许内容 流内容 , but not containing <form> 元素
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts flow content
Implicit ARIA role form if the form has an accessible name ,否则 no corresponding role
Permitted ARIA roles search , none or presentation
DOM 接口 HTMLFormElement

属性

此元素包括 全局属性 .

accept
Comma-separated content types the server accepts. This attribute was removed in HTML5 and should not be used. Instead, use the accept attribute on <input type=file> 元素。
accept-charset
Space-separated character encodings the server accepts. The browser uses them in the order in which they are listed. The default value means the same encoding as the page .
(In previous versions of HTML, character encodings could also be delimited by commas.)
autocapitalize
A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized. autocapitalize attributes on a form elements override it on <form> . Possible values:
  • none : No automatic capitalization.
  • sentences (default): Capitalize the first letter of each sentence.
  • words : Capitalize the first letter of each word.
  • characters : Capitalize all characters — that is, uppercase.
autocomplete
Indicates whether input elements can by default have their values automatically completed by the browser. autocomplete attributes on form elements override it on <form> . Possible values:
名称
The name of the form. Deprecated as of HTML 4 (use id instead). It must be unique among the forms in a document and not an empty string as of HTML5.
rel
Creates a hyperlink or annotation depending on the value, see the rel attribute for details.

Attributes for form submission

The following attributes control behavior during form submission.

action
The URL that processes the form submission. This value can be overridden by a formaction attribute on a <button> , <input type="submit"> ,或 <input type="image"> 元素。
enctype
If the value of the method 属性为 post , enctype MIME 类型 of the form submission. Possible values:
  • application/x-www-form-urlencoded : The default value.
  • multipart/form-data : Use this if the form contains <input> elements with type=file .
  • text/plain : Introduced by HTML5 for debugging purposes.

This value can be overridden by formenctype attributes on <button> , <input type="submit"> ,或 <input type="image"> 元素。

method
HTTP method to submit the form with. Possible (case insensitive) values:

This value is overridden by formmethod attributes on <button> , <input type="submit"> ,或 <input type="image"> 元素。

novalidate
This Boolean attribute indicates that the form shouldn't be validated when submitted. If this attribute is not set (and therefore the form is validated), it can be overridden by a formnovalidate attribute on a <button> , <input type="submit"> ,或 <input type="image"> element belonging to the form.
target
Indicates where to display the response after submitting the form. In HTML 4, this is the name/keyword for a frame. In HTML5, it is a name/keyword for a 浏览上下文 (for example, tab, window, or iframe). The following keywords have special meanings:
  • _self (default): Load into the same browsing context as the current one.
  • _blank : Load into a new unnamed browsing context.
  • _parent : Load into the parent browsing context of the current one. If no parent, behaves the same as _self .
  • _top : Load into the top-level browsing context (i.e., the browsing context that is an ancestor of the current one and has no parent). If no parent, behaves the same as _self .

This value can be overridden by a formtarget attribute on a <button> , <input type="submit"> ,或 <input type="image"> 元素。

范例

HTML

<!-- Form which will send a GET request to the current URL -->
<form>
  <label>Name:
    <input name="submitted-name" autocomplete="name">
  </label>
  <button>Save</button>
</form>
<!-- Form which will send a POST request to the current URL -->
<form method="post">
  <label>Name:
    <input name="submitted-name" autocomplete="name">
  </label>
  <button>Save</button>
</form>
<!-- Form with fieldset, legend, and label -->
<form method="post">
  <fieldset>
    <legend>Title</legend>
    <label><input type="radio" name="radio"> Select me</label>
  </fieldset>
</form>
								

规范

规范 状态 注释
HTML 实时标准
The definition of '<form>' in that specification.
实时标准
HTML5
The definition of '<form>' in that specification.
推荐
HTML 4.01 Specification
The definition of '<form>' in that specification.
推荐 初始定义

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
form Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
accept 弃用 Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
accept-charset Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
action Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
autocapitalize 非标 Chrome 不支持 No Edge 不支持 No Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 完整支持 Yes Samsung Internet Android 不支持 No
autocomplete Chrome 完整支持 Yes 注意事项
完整支持 Yes 注意事项
注意事项 The Google Chrome UI for auto-complete request varies, depending on whether autocomplete 被设为 off on <input> elements as well as their form. Specifically, when a form has autocomplete 设为 off 及其 <input> 元素的 autocomplete attribute is not set, then if the user asks for autofill suggestions for the <input> element, Chrome might display a message saying 'autocomplete has been disabled for this form.' On the other hand, if both the form and the input element have autocomplete 设为 off , the browser will not display that message. For this reason, you should set autocomplete to off for each <input> that has custom auto-completion.
Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
enctype Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
method Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
名称 Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
novalidate Chrome 完整支持 10 Edge 完整支持 12 Firefox 完整支持 4 IE 完整支持 10 Opera 完整支持 15 Safari 完整支持 10.1 WebView Android 完整支持 37 Chrome Android 完整支持 18 Firefox Android 完整支持 4 Opera Android 完整支持 14 Safari iOS 完整支持 10.3 Samsung Internet Android 完整支持 1.0
target Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes

图例

完整支持

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: