HTML <input> elements support several useful attributes that control the behavior, appearance, and validation of form fields. These attributes help enhance user experience and ensure proper data collection.
Below is a list of commonly used input attributes with explanations and examples.
Specifies the type of input control.
Examples: text, email, password, number, date, file, etc.
<input type="email">
Identifies the input when a form is submitted.
<input type="text" name="username">
Sets the default value inside the input.
<input type="text" value="Hello!">
Shows a hint to the user inside the input.
<input type="text" placeholder="Enter your name">
Makes the input mandatory.
<input type="email" required>
Prevents the user from editing the input (but value is submitted).
<input type="text" value="This is fixed" readonly>
Disables the input (value is not submitted).
<input type="text" disabled>
Sets character limits for text inputs.
<input type="text" minlength="3" maxlength="10">
Sets numeric or date limits.
<input type="number" min="1" max="100">
Specifies increments for number/date inputs.
<input type="number" step="5">
Sets a regular expression for validation.
<input type="text" pattern="[A-Za-z]{3,}">
Enables or disables browser autofill.
<input type="text" autocomplete="off">
Automatically focuses the input when the page loads.
<input type="text" autofocus>
Allows multiple file or email selections.
<input type="file" multiple>
Sets an input (checkbox or radio) as selected by default.
<input type="checkbox" checked>
Connects the input to a <datalist> for suggestions.
<input list="browsers">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
</datalist>