Tag Description
The input tag is used to select user information. An input field can be a text field, a checkbox, a password field, a radio button, a button, and more.
This tag has the form:
<input name="text" type="{ button | checkbox | file | hidden | image | password | radio | reset | submit | text }" value="value" />
HTML5 and HTML4.01 Differences
In HTML4.01 the "align" attribute was deprecated, and is not supported in HTML5.
HTML5 has defined new attributes.
In HTML5 the "type" attribute has a lot of new values.
HTML5 | = New for HTML5 |
Attributes
Attribute | Value | Description |
---|---|---|
accept | list_of_ mime_ types |
Specifies a comma-separated list of MIME types that indicates the MIME type of the file transfer (only for type = "file") |
align | left
right top middle bottom |
Specifies the alignment of an image input (only for type="image")
HTML4:
![]() HTML5:
![]() |
alt | text | Specifies an alternate text for an image input (only for type = "image") |
auto
completeHTML5 |
on
off |
If "on" browsers can store the form's input values, to auto-fill the form if the user returns to the page.
If "off" browsers should not store this information |
autofocusHTML5 | autofocus | Makes the field focused on page load |
checked | checked | Specifies that the input element should be preselected when the page loads (for type="checkbox" or type="radio") |
disabled | disabled | Specifies that the input element should be disabled when the page loads |
formHTML5 | form_id | Defines one ore more forms the field belongs to |
form
actionHTML5 |
URL | Specifies where to send the form-data when a form is submitted (overrides the form's action attribute) |
formenc
typeHTML5 |
application
/x-www-form-urlencoded multipart/ form-data text/plain |
Specifies how form-data should be encoded before sending it to a server (overrides the form's enctype attribute) |
form
methodHTML5 |
get
post put delete |
Specifies how to send form-data (overrides the form's action attribute) |
formno
validateHTML5 |
true
false |
Overrides the form's novalidate attribute. If "true" the input field should not be validated when submitted |
form
targetHTML5 |
_blank
_self _parent _top |
Specifies where to open the action URL (overrides the forms target attribute)
|
heightHTML5 | pixels % |
Specifies the height of the input field |
listHTML5 | id of a datalist | Reference to a datalist element. If defined, a suggestion list (drop down list?) should be displayed, with predefined opions |
maxHTML5 | number | The input field's maximum value. Use togheter with the "min" attribute to create a range of legal values |
maxlength | number | Specifies the maximum length (in characters) of an input field (for type="text" or type="password") |
minHTML5 | number | The input field's minimum value. Use togheter with the "max" attribute to create a range of legal values |
multipleHTML5 | multiple | If present the user is allowed more than one value |
name | name | Specifies a name for an input element |
patternHTML5 | JS Pattern | Defines a pattern or format for the input field's value. Example: pattern="[0-9]" means that the input value must be a number between 0 an 9. Use the standard "title" attribute to describe the pattern |
placeholderHTML5 | text | Defines a hint to help users fill out the input field |
readonly | readonly | Specifies that an input field should be read-only (for type="text" or type="password") |
requiredHTML5 | required | Defines if the input field's value is required in order to submit the form
Note: Cannot be used with type: hidden, image, button, submit, reset |
size | number | Specifies the width of an input field |
src | URL | Specifies the URL to an image to display as a submit button |
stepHTML5 | number any |
(only when type = date, datetime, datetime-local, month, week, time, number, or range) |
type | button
checkbox color date datetime datetime-local file hidden image month number password radio range reset search submit tel text time url week |
Specifies the type of the input element (default = "text") |
value | value | Specifies the value of the input element |
widthHTML5 | pixels % |
Specifies the width of the input field |
Global Attributes
This tag also supports the HTML Global Attributes.
Event Attributes
This tag also supports the HTML Event Attributes.
Examples
The following example shows the basic use of this tag:
<form action="form_action.asp" method="get">
First name:
<input type="text" name="fname" />
Last name:
<input type="text" name="lname" />
<input type="submit" value="Submit" />
</form>
This produces the following result:
Browser Support
Chrome | Firefox | IE | Safari | Opera |
---|---|---|---|---|
Doctype Declaration Support
The following table lists the doctype declarations this element may appear in:
HTML4.01 / XHTML1.0 | XHTML 1.1 | HTML 5 | ||
---|---|---|---|---|
Traditional | Strict | Frameset | ||
Miscellaneous Information
Defined In: | HTML 2 |
---|---|
Empty Tag: | Yes |