Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML input tag

HTML tag

Example

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

<form action="demo_form.php">

First name:

<input type="text" name="fname">
<br>

Last name:

<input type="text" name="lname">
<br>
<input type="submit" value="Submit" form>

Try it »

(You can find more examples at the bottom of this page)


Browser support

Element
Yes Yes Yes Yes Yes

Tag Definition and Usage Notes

The tag specifies an input field where the user can enter data.

The element is used in

the element to declare an input control that allows the user to enter data.

The input field can be changed in several ways, depending on the type attribute.


Tips and Notes

**Note: ** The element is empty; it contains only attributes.

Tip: You can use the the element to define the label for the element.


Differences between HTML 4.01 and HTML5

In HTML 4.01, the "align" attribute is no longer used. It is not supported in HTML5. You can use CSS to define the alignment of the element.

In HTML5, several attributes have been added, along with their corresponding values.


Differences between HTML and XHTML

In HTML, the tag has no end tag.

In XHTML, The tag must be closed properly.


property

New: new tag in HTML5.

property Value Description
accept audio/* video/* image/* MIME_type Specifies the type of file to be submitted via file upload. (Only for type="file")
align left right top middle bottom Deprecated in HTML5 and no longer recommended. Specifies the alignment of the image input. (Only for type="image")
alt text Defines alternative text for the image input. (Only for type="image")
autocompleteNew on off The autocomplete attribute specifies whether the input field of the element should have autocomplete enabled.
autofocusNew autofocus The attribute specifies that the element should automatically get focus.
checked checked The checked attribute specifies that the element receives focus when the page loads. (Only for type="checkbox" or type="radio")
disabled disabled The disabled attribute specifies the element to be disabled. .
formNew form_id The form attribute specifies the one or more forms to which the element belongs.
formactionNew URL The attribute specifies the URL of the file that processes the input control when the form is submitted. (Only for type="submit" and type="image")
formenctypeNew application/x-www-form-urlencoded multipart/form-data text/plain The attribute specifies how form data is encoded when submitted to the server (only for type="submit" and type="image").
formmethodNew get post Defines the HTTP method used to send form data to the action URL. (Only for type="submit" and type="image")
formnovalidateNew formnovalidate The formnovalidate attribute overrides the novalidate attribute of the element.
formtargetNew _blank _self _parent _top framename Specifies the name or keyword indicating where to display the received response after submitting the form. (Only for type="submit" and type="image")
heightNew pixels Specifies the the height of the element. (Only for type="image")
listNew datalist_id The attribute references element, which contains the predefined options for the element.
maxNew number date The attribute specifies maximum value of the element.
maxlength number The attribute specifies maximum number of characters allowed in the element.
minNew number date The attribute specifies minimum value of the element.
multipleNew multiple The attribute specifies what the user is allowed to enter into element.
name text The name attribute specifies The name of the element.
patternNew regexp The pattern attribute specifies the regular expression used to validate the element's value.
placeholderNew text The placeholder attribute specifies a short hint that describes the expected value of the input field.
readonly readonly The readonly attribute specifies that the input field is read-only.
requiredNew required The attribute specifies that the input field must be filled in before submitting the form.
size number The size attribute specifies the visible width of the element, measured in number of characters.
src URL The src attribute specifies the URL of the image displayed as the submit button. (Only for type="image")
stepNew number The step attribute specifies the legal number interval of the element.
type button
 checkbox       

 color       

 date       

 datetime       

 datetime-local       

 email       

 file       

 hidden       

 image       

 month       

 number       

 password       

 radio       

 range       

 reset       

 search       

 submit       

 tel       

 text       

 time       

 url       

 week | type 属性Specifies要显示的  元素的类型。 |

| value | text | Specifies the value of the element's value attribute. ** ** | | widthNew | pixels | The width attribute specifies the width of the element. (Only for type="image") |


Global Attributes

The tag supports global attributes; see the full list in HTML Global Attributes.


Event attribute

The tag supports all HTML Event Attributes.