<input>
HTML <input> 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
Most browsers currently support the <input> tag.
Tag definition and usage instructions
<input> Tags specify input fields in which users can enter data.
The<input> element is used in the <form> element to declare an input control that allows users to enter data.
Input fields can be changed in a variety of ways, depending on the type attribute.
Tips and Notes
Note: The <input> element is empty, it only contains the label attribute.
Tip: You can use the <label> element to define the label of the <input> element.
Differences between HTML 4.01 and HTML5
In HTML 4.01, "align" data is no longer used. This attribute is not supported in HTML5. You can use CSS to define the alignment of the <input> element.
In HTML5, <input> adds several attributes and corresponding values.
Differences between HTML and XHTML
In HTML, the <input> tag does not have a closing tag.
In XHTML, the <input> tag must be closed properly.
Attribute
New: HTML5 new tag.
Attributes | Value | Description |
---|---|---|
accept | audio/* video/* image/*MIME_type | Specifies the type of file submitted through file upload. (only for type="file") |
align | left right top middle bottom | HTML5 is obsolete and deprecated. Specifies the alignment of the image input. (Only for type="image") |
alt | text | Define the alternative text for image input . (Only for type="image") |
autocompleteNew | on The off | autocomplete attribute specifies whether the <input> element input field should have autocomplete enabled. The |
autofocusNew | autofocus | attribute specifies that the <input> element should automatically gain focus when the page loads. |
checked | checked | The checked attribute specifies which <input> elements should be pre-selected when the page loads. (Only for type="checkbox" or type="radio") |
disabled | disabled | disabled attribute specifies the<input> that should be disabled ; element. |
formNew | form_id | The form attribute specifies the one to which the <input> element belongs or multiple forms. |
formactionNew | URL | # property specifies the file that handles the input control when the form is submitted. URL. (only for type="submit" and type="image") |
formenctypeNew | application/x-www-form-urlencoded multipart/form-data The text/plain | attribute specifies how form data is encoded when submitted to the server (only suitable for type="submit" and type="image"). |
formmethodNew | get post | Define the HTTP method that sends form data to the action URL. (Only suitable for type="submit" and type="image") |
formnovalidateNew | formnovalidate | formnovalidate attribute Overrides the novalidate attribute of the <form> element. |
formtargetNew | _blank _self _parent _topframename | specifies where to display the name or keyword of the response received after submitting the form. (Only suitable for type="submit" and type="image") |
heightNew | pixels | Specifies the height of the <input> element.(Only for type="image") |
listNew | ##datalist_id | Attribute reference <datalist> element that contains predefined options for the <input> element.|
New | number The date | attribute specifies the maximum value of the <input> element. The|
number | attribute specifies the maximum number of characters allowed in the <input> element.||
New | number The date | attribute specifies the minimum value of the <input> element. The|
New | multipleattribute specifies that the user is allowed to enter multiple values into the <input> element. | |
text | The name attribute specifies the name of the <input> element.||
New | ##regexpThe pattern attribute specifies the value used to validate the <input> element Regular expression for the value. | |
text | placeholder attribute specifies an input<input> field that can be described A short message about the expected value . | |
readonly | The readonly attribute specifies that the input field is read-only. The | |
required | # attribute specifies that the input field must be filled in before the form is submitted. | |
number | The size attribute specifies the visible width of the <input> element in characters. | |
URL | The src attribute specifies the URL of the image that appears as a submit button. (only for type="image") | |
number | step attribute specification< Legal numeric intervals for input> elements. | |
button | checkboxcolor date datetime datetime-local file hidden image month number password radio range reset search submit tel text## The #time url week type attribute specifies the type of <input> element to be displayed. | value |
text | Specifies the value of the <input> element value. | width |
pixels | The width attribute specifies the width of the <input> element. (Only for type="image") |
<input> tag supports global attributes, view the complete attributes Table HTML global properties.
Event attributes
<input> tag supports all HTML event attributes.