The HTML <input> Tag
Definition and usage
<input>
The tag defines an input field where users can enter data.
<input>
The element is the most important form element.
<input>
The element can be displayed in various ways, depending on type attribute.
The following are different input types:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
(Default value)<input type="time">
<input type="url">
<input type="week">
See also type attributeTo view examples of each input type!
Example
An HTML form containing three input fields; two text fields and a submit button:
<form action="/action_page.php"> <label for="fname">Name:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">Surname:</label> <input type="text" id="lname" name="lname"><br><br> <input type="submit" value="Submit"> </form>
Tips and comments
Tip:Always use the <label> tag to define labels for the following elements:
<input type="text"> <input type="checkbox"> <input type="radio"> <input type="file"> <input type="password">
Attribute
Attribute | Value | Description |
---|---|---|
accept |
|
Specifies the type of file to be submitted through file upload. Specifies the file type filters that the user can select from the file input dialog (only for type="file"). |
alt | Text | Specifies the alternative text for the image (only for type="image"). |
autocomplete |
|
Specifies whether the <input> element should enable automatic completion. |
autofocus | autofocus | Specifies that the <input> element should automatically receive focus when the page is loaded. |
checked | checked | Specifies that the <input> element should be pre-selected when the page is loaded (for type="checkbox" or type="radio"). |
dirname | inputname.dir | Specifies the text direction that will be submitted. |
disabled | disabled | Specifies that the <input> element should be disabled. |
form | Form id | Specifies the form that the <input> element belongs to. |
formaction | URL | Specifies the URL to be used for handling the file input controls when submitting the form (for type="submit" and type="image"). |
formenctype |
|
Specifies how the form data should be encoded when submitted to the server (applicable to type="submit" and type="image"). |
formmethod |
|
Defines the HTTP method used to send data to the action URL (applicable to type="submit" and type="image"). |
formnovalidate | formnovalidate | Defines that the form should not be validated when submitting the form element. |
formtarget |
|
Specifies where the response received after submitting the form should be displayed (applicable to type="submit" and type="image"). |
height | Pixels | Specifies the height of the <input> element (only applicable to type="image"). |
list | datalist_id | References the <datalist> element containing the predefined options for the <input> element. |
max |
|
Specifies the maximum value of the <input> element. |
maxlength | number | Specifies the maximum number of characters allowed in the <input> element. |
min |
|
Specifies the minimum value of the <input> element. |
minlength | number | Specifies the minimum number of characters required in the <input> element. |
multiple | multiple | Specifies that the user can enter multiple values in the <input> element. |
name | Text | Specifies the name of the <input> element. |
pattern | Regular expression | Specifies the regular expression to check the value of the <input> element. |
placeholder | Text | Specifies a brief hint for the expected value of the <input> element. |
popovertarget | Element id | Specifies the popup element to be called (only applicable to type="button"). |
popovertargetaction |
|
Specifies what happens when you click the button (only applicable to type="button"). |
readonly | readonly | Specifies that the input field is read-only. |
required | required | Specifies that the input field must be filled out before submitting the form. |
size | number | Specifies the width of the <input> element (in terms of character count). |
src | URL | The URL used for the image of the submit button (only applicable to type="image"). |
step |
|
Specifies the interval between valid numbers in the input field. |
type |
|
Specifies the type of the <input> element to be displayed. |
value | Text | Specifies the value of the <input> element. |
width | Pixels | Specifies the width of the <input> element (only applicable to type="image"). |
Global Attributes
<input>
Tags also support Global Attributes in HTML.
Event Attributes
<input>
Tags also support Event Attributes in HTML.
Default CSS Settings
None.
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
Related Pages
HTML Tutorial:
HTML DOM Reference Manual:
- Input Button Object
- Input Checkbox Object
- Input Color Object
- Input Date Object
- Input Datetime Object
- Input DatetimeLocal Object
- Input Email Object
- Input FileUpload Object
- Input Hidden Object
- Input Image Object
- Input Month Object
- Input Number Object
- Input Password Object
- Input Range Object
- Input Radio Object
- Input Reset Object
- Input Search Object
- Input Submit Object
- Input Text Object
- Input Time Object
- Input URL Object
- Input Week Object