<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

1000.png

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.

Attribute reference <datalist> element that contains predefined options for the <input> element. max attribute specifies the maximum value of the <input> element. The maxlength attribute specifies the maximum number of characters allowed in the <input> element. min attribute specifies the minimum value of the <input> element. The multiplemultiple attribute specifies that the user is allowed to enter multiple values ​​into the <input> element. name The name attribute specifies the name of the <input> element. pattern##regexpplaceholderNewtextreadonlyrequiredNewsizenumbersrcURLstepNewnumbertypecheckboxvaluewidthNew
AttributesValueDescription
acceptaudio/* video/* image/*MIME_typeSpecifies the type of file submitted through file upload. (only for type="file")
alignleft right top middle bottomHTML5 is obsolete and deprecated. Specifies the alignment of the image input. (Only for type="image")
alttextDefine the alternative text for image input . (Only for type="image")
autocompleteNewon The offautocomplete attribute specifies whether the <input> element input field should have autocomplete enabled. The
autofocusNewautofocus attribute specifies that the <input> element should automatically gain focus when the page loads.
checkedcheckedThe checked attribute specifies which <input> elements should be pre-selected when the page loads. (Only for type="checkbox" or type="radio")
disableddisableddisabled attribute specifies the<input> that should be disabled ; element.
formNewform_id The form attribute specifies the one to which the <input> element belongs or multiple forms.
formactionNewURL# property specifies the file that handles the input control when the form is submitted. URL. (only for type="submit" and type="image")
formenctypeNewapplication/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").
formmethodNewget postDefine the HTTP method that sends form data to the action URL. (Only suitable for type="submit" and type="image")
formnovalidateNewformnovalidateformnovalidate 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")
heightNewpixelsSpecifies the height of the <input> element.(Only for type="image")
listNew##datalist_id
Newnumber The date
number
Newnumber The date
New
text
New The pattern attribute specifies the value used to validate the <input> element Regular expression for the value.
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.
The size attribute specifies the visible width of the <input> element in characters.
The src attribute specifies the URL of the image that appears as a submit button. (only for type="image")
step attribute specification< Legal numeric intervals for input> elements.
buttoncolor
date
datetime
datetime-local
email
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.
textSpecifies the value of the <input> element value.
pixels The width attribute specifies the width of the <input> element. (Only for type="image")
Global attributes

<input> tag supports global attributes, view the complete attributes Table HTML global properties.

Event attributes


<input> tag supports all HTML event attributes.