English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML: <input> tag

The HTML <input> tag is an interactive control that provides users with input controls for entering data. Traditionally, the <input> tag is located within the <form> tag and can be used to represent text fields, checkboxes, dropdown menus, buttons, and other inputs by setting the appropriate type attribute. This tag is also commonly referred to as the <input> element.

Online Example

A simple HTML form that includes two text input fields and a submit button:

!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML5 Usage of footer tag (Basic Tutorial Website oldtoolbag.com)</title>/title>
</head>
<body>
<h1>oldtoolbag.com basic tutorial</h1>
<form action="demo-form.php" method="post">
  Company: <input type="text" name="company"><br>
  Address: <input type="text" name="address"><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>
Test and see ‹/›

In this HTML5In the document example, we used the <form> tag to create an HTML form. This form includes two <input> controls for company and address, and one <input> control for the submit button.

Browser Compatibility

IEFirefoxOperaChromeSafari

Most browsers support the <input> tag.

Definition and usage instructions for the tag

The <input> tag specifies the input field where users can enter data.

The <input> element is used within the <form> element to declare input controls that allow users to enter data.

By setting the type attribute, the <input> element can become a text field, checkbox, radio button, dropdown menu, button, password field, and more!

Hints and Notes

Note: The <input> element is empty, it only contains label attributes.

Hint: You can use <label> An element to define the annotation of the <input> element.

HTML 4.01 With HTML5Differences

In HTML 4.01 In, "align" data is no longer used. HTML5 Does not support this attribute. CSS can be used to define the alignment of the <input> element.

In HTML5In, <input> added 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 correctly.

Attribute

New : HTML5New tag.

AttributeValueDescription
acceptaudio/* video/* image/*MIME_typeSpecifies the type of file to be submitted via file upload. (Only for type="file")
alignleft right top middle bottomHTML5Deprecated, not recommended for use. Specifies the alignment of image inputs. (Only for type="image")
alttextDefines alternative text for image inputs. (Only for type="image")
autocompleteHTML5on offThe autocomplete attribute specifies whether the automatic completion feature should be enabled for the input field of the <input> element.
autofocusHTML5autofocusThe attribute specifies that the <input> element should automatically gain focus when the page is loaded.
checkedcheckedThe checked attribute specifies that the <input> element should be pre-selected when the page is loaded. (Only for type="checkbox" or type="radio")
dirnameHTML5inputname.dirSpecifies the text direction for the submitted text.
disableddisabledThe disabled attribute specifies the <input> element that should be disabled.
formHTML5form_idThe form attribute specifies one or more forms to which the <input> element belongs.
formactionHTML5URLThe attribute specifies the URL to process the file of the input control when the form is submitted. (Only applicable to type="submit" and type="image")
formenctypeHTML5application/x-www-form-urlencoded multipart/form-data text/plainThe attribute specifies how the form data is encoded when submitted to the server (only suitable for type="submit" and type="image")
formmethodHTML5get postIt defines the HTTP method to send form data to the action URL. (Only suitable for type="submit" and type="image")
formnovalidateHTML5formnovalidateThe 'formnovalidate' attribute overrides the 'novalidate' attribute of the <form> element.
formtargetHTML5_blank _self _parent _topframenameIt specifies the name or keyword where the received response will be displayed after submitting the form. (Only suitable for type="submit" and type="image")
heightHTML5pixelsIt specifies the height of the <input> element. (Only applicable to type="image")
listHTML5datalist_idThe attribute references the <datalist> element, which contains predefined options for the <input> element.
maxHTML5number dateThe attribute specifies the maximum value of the <input> element.
maxlengthnumberThe attribute specifies the maximum number of characters allowed in the <input> element.
minHTML5number dateThe attribute specifies the minimum value of the <input> element.
multipleHTML5multipleThe attribute specifies that multiple values are allowed to be entered into the <input> element.
nametextThe 'name' attribute specifies the name of the <input> element.
patternHTML5regexpThe 'pattern' attribute specifies the regular expression used to validate the value of the <input> element.
placeholderHTML5textThe 'placeholder' attribute specifies a brief hint that describes the expected value of the input <input> field. .
readonlyreadonlyThe 'readonly' attribute specifies that the input field is read-only.
requiredHTML5requiredThe attribute specifies that the input field must be filled out before submitting the form.
sizenumberThe 'size' attribute specifies the visible width of the <input> element in terms of character count.
srcURLThe 'src' attribute specifies the URL of the image to be displayed as a submit button. (Only applicable to type="image")
stepHTML5numberThe step attribute specifies the legal numeric interval for the <input> element.
typebutton
checkbox
color
date
datetime
datetime-local
email
file
hidden
image
month
number
password
radio
range
reset
search
submit
tel
text
time
url
week
The type attribute specifies the type of the <input> element to be displayed.
valuetextSpecifies the value of the <input> element's value.
widthHTML5pixelsThe width attribute specifies the width of the <input> element. (Only for type="image")

Global Attributes

<input> tag supports global attributes, see the complete attribute table HTML Global Attributes.

event attributes

<input> tag supports all HTML Event Attributes.