HTML5 <input> Tag
ExampleA simple HTML form with two input fields and one submit button:
Try it yourself » |
Definition and Usage
The <input> tag specifies an input field where the user can enter data.
Differences Between HTML 4.01 and HTML5
In HTML 4.01 the "align" attribute was deprecated, and is not supported in HTML5, use CSS to align input elements.
The <input> tag in HTML5 has many new attributes.
The type attribute in HTML5 has many new values.
Tips and Notes
Note: The input element is empty, it contains attributes only.
Tip: Use the label element to define a label to a form control.
Attributes
New : New in HTML5.
Attribute | Value | Description |
---|---|---|
accept | list_of_mime_types | A comma-separated list of MIME types that indicates the MIME type of the file transfer. Note: Only used with type="file" |
alt | text | Defines an alternate text for the image. Note: Only used with type="image" |
autocompleteNew | on off |
Specifies whether or not the the input field should have autocomplete enabled. |
autofocusNew | autofocus | Makes the input field focused on page load. Note: Cannot be used with type="hidden" |
checked | checked | Indicates that the input element should be checked when it first loads. Note: Used with type="checkbox" and type="radio" |
disabled | disabled | Disables the input element when it first loads so that the user can not write text in it, or select it. Note: Cannot be used with type="hidden" |
formNew | formname | Defines one ore more forms the input field belongs to |
formactionNew | URL | Overrides the form's action attribute. Must be a valid URL that defines where to send the data when the form is submitted. Note: Used with type="submit" and type="image" |
formenctypeNew | application/x-www-form-urlencoded multipart/form-data text/plain |
Overrides the form's enctype attribute. Specifies how form-data should be encoded before sending it to the server. Note: Used with type="submit" and type="image" |
formmethodNew | get post |
Overrides the form's method attribute. Defines the HTTP method for sending data to the action URL. Note: Used with type="submit" and type="image" |
formnovalidateNew | formnovalidate | Overrides the form's novalidate attribute. If present the input field should not be validated when submitted |
formtargetNew | _blank _self _parent _top framename |
Overrides the form's target attribute. Specifies the target window used when the form is submitted. Note: Used with type="submit" and type="image" |
heightNew | pixels % |
Defines the height of an input. Note: Only used with type="image" |
listNew | datalist-id | Refers to a datalist containing predefined options for the input field |
maxNew | number date |
The input field's maximum value. Use together with the "min" attribute to create a range of legal values |
maxlength | number | Defines the maximum number of characters allowed in a text field |
minNew | number date |
The input field's minimum value. Use together with the "max" attribute to create a range of legal values |
multipleNew | multiple | If present the user is allowed more than one value |
name | fieldname | Defines a name for the input element. The name attribute is used to collect the fields value when submitted |
patternNew | regexp_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 |
placeholderNew | text | Defines a hint to help users fill out the input field |
readonly | readonly | Indicates that the value of this field cannot be modified |
requiredNew | required | Defines if the input field's value is required in order to submit the form. |
size | number of characters | Defines how many characters should be visible in the input field. |
src | URL | Defines the URL of the image to display. Use with type="image" |
stepNew | number | Specifies the legal number intervals for the input field |
type | button checkbox color date datetime datetime-local file hidden image month number password radio range reset search submit tel text time url week |
Indicates the type of the input element. The default value is "text". |
value | value | For buttons: Defines the text on the button. For image buttons: Defines the symbolic result of the field passed to a script. For checkboxes and radio buttons: Defines the result of the input element when clicked. The result is sent to the form's action URL. For hidden, password, and text fields: Defines the default value of the element. Note: Cannot be used with type="file" Note: This attribute is required with type="checkbox" and type="radio" |
widthNew | pixels % |
Defines the width of an input. Note: Only used with type="image" |
Standard Attributes
The <input> tag also supports the Standard Attributes in HTML5.
Event Attributes
The <input> tag also supports the Event Attributes in HTML5.