HTML <input> Tag
Description
The HTML <input> element is used to create interactive controls for web forms. It is one of the most versatile HTML elements, with many different types available including text, password, email, number, checkbox, radio, and more.
The <input> element is a void element (self-closing) and its behavior changes dramatically based on the type attribute.
inline-blockSyntax
<input type="text" name="fieldname" placeholder="Enter text">Popular Attributes
| Attribute | Description |
|---|---|
| typeRequired | Specifies the type of the element. Behavior changes based on the type value. |
| name | The name of the form control, used to identify the field when submitting form data. |
| value | The initial or current value of the element. |
| placeholder | A hint displayed in the input field before the user enters a value. |
| required | When present, the user must fill in the field before submitting the form. |
| disabled | Disables the element, preventing user interaction and excluding it from form submission. |
| readonly | Makes the field read-only — the user can see but not modify the value. |
| maxlength | Specifies the maximum number of characters allowed in the input. |
This element also supports global HTML attributes such as class, id, style, data-*, and more.
Examples
Notes
Always associate <input> elements with a <label> element for accessibility. You can do this by wrapping the input in a label or by using the for attribute on the label matching the input's id.
Use the appropriate type attribute for better mobile UX — for example, type="email" shows an optimized keyboard on mobile devices.