<input> Tag
The <input> tag represents an interactive control used to accept input from users.
It offers a wide range of control types based on the value of its type attribute, and its behavior can be finely customized using various additional attributes.
By combining these attributes, the <input> tag provides a wide range of powerful features.
The contents are structured as follows:
Demo Example
The <input> tag is a void element, meaning it cannot have any content and does not have a closing tag (</input>).
<form action="submit_url" method="get" class="form-example">
<div class="form-example">
<label for="user-name">Name</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="form-example">
<label for="user-email">Email</label>
<input type="email" id="user-email" name="user-email" required>
</div>
<input type="submit">
</form>
Code Explanation
The <form> tag represents an
area of a web form for submitting data.
This area contains control elements related to web forms and is used to define a form for submitting the data from these elements.
type Attribute
The <input> tag offers a wide range of control types based on the value of its type attribute.
type attribute values not supported by some major browsers have been excluded.
type |
Description | Basic Example |
|---|---|---|
<input type="button"> |
This is a button with no default behavior.
It can be used with JavaScript to perform various actions. |
|
<input type="checkbox"> |
This is a checkbox.
It allows a single value to be checked and unchecked. It is generally square, but its corners may be rounded. |
|
<input type="color"> |
This is an input field in the form of a color picker that allows the user to select or enter a color.
It opens a color picker when activated in the browser. |
|
<input type="date"> |
This is a date input control.
It opens a date picker or numeric wheel for the year, month, and day when activated in the browser. |
|
<input type="datetime-local"> |
This is an input field that provides a date and time selection interface for easily entering a date and time at once. | |
<input type="email"> |
This is an email address input field.
It looks like a text input, but on some devices with dynamic virtual keyboards (such as mobile devices), it supports a keyboard that helps with entering email addresses such as the @ and . characters. |
|
<input type="file"> |
This is an input field that allows users to select and upload files from their devices. | |
<input type="hidden"> |
This is a hidden input field that is not visible to users but allows data to be submitted along with the form. | |
<input type="image"> |
This is a form (<form>) submit button displayed as an image rather than text.
Clicking this button submits the values of all submittable controls in the form containing the element. |
|
<input type="number"> |
This is a numeric input field.
It displays a spinner and performs validation to allow only numbers to be entered. On some devices with dynamic virtual keyboards (such as mobile devices), it displays a numeric keypad. |
|
<input type="password"> |
This is a password input field.
The browser hides sensitive information entered by the user by replacing text characters with symbols such as bullets (•), making them unreadable on the screen. |
|
<input type="radio"> |
This is a radio button.
It is generally rendered as a small circle and is filled or highlighted when selected. |
|
<input type="range"> |
This is a range slider that allows a value to be selected within a specified numeric range. | |
<input type="reset"> |
This is a form (<form>) reset button.
When this button is clicked, it resets the values of all controls in the form containing this element. |
|
<input type="search"> |
This is a search term input field.
It is a single-line text input control, and on some devices with dynamic virtual keyboards (such as mobile devices), it supports a search icon. Depending on the browser, it may include a delete icon that can be used to clear the field. |
|
<input type="submit"> |
This is a form (<form>) submit button.
Clicking this button submits the values of all submittable controls in the form containing the element. |
|
<input type="tel"> |
This is a phone number input field.
It is a single-line text input control and does not validate the phone number format. |
|
<input type="text"> |
This is the default value of the type attribute and is a general text input field.
It is a single-line text input control. |
|
<input type="time"> |
This is an input control that provides a time selection interface for easy entry of a time. | |
<input type="url"> |
This is a URL input field.
It looks like a text input, but on some devices with dynamic virtual keyboards (such as mobile devices), it supports a keyboard that helps with entering URLs, with keys for characters such as / and . and keys for quickly entering strings commonly found in domain names, such as www. or .com. |
Good to Know!
The interface or styling of a control based on the value of the type attribute may vary slightly depending on the browser and operating system.
Browser Compatibility
| Attribute Value |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
type="button"
|
1 | 12 | 1 | 1 |
type="checkbox"
|
1 | 12 | 1 | 1 |
type="color"
|
20 | 14 | 29 | 12.1 |
type="date"
|
20 | 12 | 53 | 14.1 |
type="datetime-local"
|
20 | 12 | 93 | 14.1 |
type="email"
|
5 | 12 | 1 | 5 |
type="file"
|
1 | 12 | 1 | 1 |
type="hidden"
|
1 | 12 | 1 | 1 |
type="image"
|
1 | 12 | 1 | 1 |
type="number"
|
7 | 12 | 29 | 5.1 |
type="password"
|
1 | 12 | 1 | 1 |
type="radio"
|
1 | 12 | 1 | 1 |
type="range"
|
4 | 12 | 23 | 3.1 |
type="reset"
|
1 | 12 | 1 | 1 |
type="search"
|
5 | 12 | 4 | 10.6 |
type="submit"
|
1 | 12 | 1 | 1 |
type="tel"
|
3 | 12 | 1 | 4 |
type="text"
|
1 | 12 | 1 | 1 |
type="time"
|
20 | 12 | 57 | 14.1 |
type="url"
|
1 | 12 | 1 | 1 |
Various Attributes
The <input> tag offers a wide range of attributes, making it exceptionally useful.
Among them, the most important is the type attribute, which was covered earlier with various examples. All <input> tags share the same basic attributes, but in practice, many attributes affect only specific type attributes. Additionally, some attributes function differently depending on the type attribute.
The <input> tag supports all global attributes.
This section provides a summary table of the main attributes of the <input> tag, followed by detailed explanations of each attribute and the specific input types it is associated with.
| Attribute | Related type Attribute Values |
Description |
|---|---|---|
accept |
file |
Specifies the allowed file types for the file upload control. |
alt |
image |
Alternative text for the src attribute. If the src attribute is missing, the value of the alt attribute is displayed, and it is required for accessibility. |
autocapitalize |
text, search, tel |
This attribute is a global attribute.
It specifies how text entered or modified by the user is automatically capitalized. It has no effect when entering text with a physical keyboard and instead applies only to voice input, virtual keyboards on mobile devices, and similar input methods. This attribute is an enumerated attribute with the following possible values.
|
autocomplete |
checkbox, radio, and all values except those related to buttons |
Specifies whether autocomplete functionality is enabled for the control.
|
checked |
checkbox, radio |
Specifies whether a checkbox is checked by default. Use the checked attribute to have the checkbox start in a checked state when the page initially loads. However, the checked attribute does not change when the user checks or unchecks the checkbox after the page has loaded.
This attribute is a Boolean attribute. The attribute is specified without a separate value. |
disabled |
All values | Indicates that the control is disabled.
This attribute is a Boolean attribute. The attribute is specified without a separate value. |
form |
All values | Associates the control with a form element. |
list |
text, search, url, tel, email, date, month, week, time, datetime-local, number, range, color |
Specifies the value of the id attribute of the <datalist> tag that provides a list of predefined options. |
max |
date, time, datetime-local, number, range |
Specifies the maximum value of the control. |
maxlength |
text, search, url, tel, email, password |
Limits the maximum number of characters (Maximum length) that the user can enter. |
min |
date, time, datetime-local, number, range |
Specifies the minimum value of the control. |
minlength |
text, search, url, tel, email, password |
Specifies the minimum number of characters (Minimum length) that the user must enter. |
multiple |
file, email |
Allows multiple values to be selected or entered at the same time.
This attribute is a Boolean attribute. The attribute is specified without a separate value. |
name |
All values | Specifies the name of the control. |
pattern |
text, search, url, tel, email, password |
Specifies the regular expression used to validate the text value of the control. |
placeholder |
text, search, url, tel, email, password, number |
Specifies the text displayed in the control when no value has been set. This value should provide the user with a brief hint about the expected type of data to be entered into the control. |
readonly |
Text-related values (text, password, search, url, tel, email, number, date, time, datetime-local, month, week) |
Makes the element read-only so that the user cannot edit it.
This attribute is a Boolean attribute. The attribute is specified without a separate value. |
required |
hidden, range, color, and all values except those related to buttons |
Indicates that the user must specify an input value for the control before submitting the form.
This attribute is a Boolean attribute. The attribute is specified without a separate value. |
size |
text, search, url, tel, email, password |
Specifies the width of a single-line text input field based on the number of characters.
This value must be a valid integer greater than 0 and not negative. |
src |
image |
Specifies the path to the image. |
step |
date, time, datetime-local, number, range |
Specifies the increment or decrement step for the numeric value of the control. |
value |
All values except file and image |
The value of the control element.
The meaning of the value is defined according to the type represented by the type attribute of this element. |
Basic Examples
Below are some basic examples of the attributes described in the table above.
checked
This attribute specifies whether a checkbox is selected by default. To have the checkbox start in a selected state when the page initially loads, use the checked attribute. However, the checked attribute does not change when the user selects or deselects the checkbox after the page has loaded.
This attribute is a Boolean attribute. The attribute is specified without a separate value.
<input type="checkbox" checked>
<input type="radio" checked>
disabled
The disabled attribute indicates that the control is disabled. This attribute is a Boolean attribute. The attribute is specified without a separate value.
<label for="user-id">ID</label>
<input type="text" id="user-id" disabled>
placeholder
The placeholder attribute specifies the text displayed in a text input control when no value has been set. This is called "placeholder text."
This value should provide the user with a brief hint about the expected type of data to be entered into the control. When the user starts entering text, the placeholder text disappears from the text input field.
<label for="user-company">Company Name</label>
<input type="text" id="user-company" placeholder="e.g., ABC Corp.">
value, min, max, step
The value attribute is the value of the control element. The meaning of the value is defined according to the type represented by the type attribute of this element.
The min attribute specifies the minimum value of the control.
The max attribute specifies the maximum value of the control.
The step attribute specifies the increment or decrement step for the numeric value of the control.
<label for="user-number">Select Quantity</label>
<input type="number" id="user-number" value="4" min="0" max="20" step="2">
Browser Compatibility
Last updated:
| Attribute |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
accept
|
1 | 12 | 1 | 1 |
alt
|
1 | 12 | 1 | 1 |
autocapitalize
|
4 | 79 | 111 | No |
autocomplete
|
14 | 79 | 4 | 6 |
checked
|
1 | 12 | 1 | 1 |
disabled
|
1 | 12 | 1 | 1 |
form
|
1 | 12 | 1 | 1 |
max
|
4 | 12 | 16 | 5 |
maxlength
|
1 | 12 | 1 | 1 |
min
|
4 | 12 | 16 | 5 |
minlength
|
40 | 17 | 51 | 10.1 |
name
|
1 | 12 | 1 | 1 |
pattern
|
4 | 12 | 4 | 5 |
placeholder
|
3 | 12 | 4 | 4 |
readonly
|
1 | 12 | 1 | 1 |
required
|
4 | 12 | 4 | 5 |
size
|
1 | 12 | 1 | 1 |
src
|
1 | 12 | 1 | 1 |
step
|
5 | 12 | 16 | 5 |
Accessibility Considerations
Control elements refer to elements that allow users to interact with a web page.
These include elements such as <input>, <textarea>, <button>, and <select>, which enable users to perform actions like entering, selecting, and submitting data.
When using control elements such as the <input>, <textarea>, and <select> tags, they should always be paired with a <label> tag.
This is a minimum requirement for accessibility.
Benefits of Using the <label> Tag with Control Elements
Associating the <label> with a Control Element
<!--
# The id value "user-checking" of the control element to be associated
# is specified as the value of the for attribute of the label tag.
-->
<label for="user-checking">Click me.</label>
<input type="checkbox" id="user-checking">
When associated this way, clicking the text of the <label> ("Click me.") causes the associated checkbox to receive focus.
<label> ("Click me.") focuses the associated checkbox.
<label>
Click me.
<input type="checkbox">
</label>
<label> ("Click me.") focuses the associated checkbox.
Both approaches above are shown as valid examples in the specification.
Technical Summary
| Permitted parents | Any element that accepts phrasing content |
|---|---|
| Permitted content | None; it is a void element. |
Implicit ARIA role |
|
Permitted ARIA roles |
|
Specifications
| Specification | |
|---|---|
<input>
|
HTML Standard #the-input-element |
See Also
- HTML <form> Tag – The Form Element
- HTML <fieldset> Tag – The Field Set Element
- HTML <textarea> Tag – The Textarea Element
- HTML <select> Tag – The Select Element
- HTML <button> Tag – The Button Element
- HTML enterkeyhint Attribute – Specifying the Enter key action for virtual keyboards
- HTML inputmode Attribute – Specifying the Virtual Keyboard Input Mode
- CSS appearance Property – Control Default Browser UI Appearance