learn2kode.in

HTML Input Attributes

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.

1. type

Specifies the type of input control.

Examples: text, email, password, number, date, file, etc.

Output

2. name

Identifies the input when a form is submitted.

<input type="text" name="username">

Output

3. value

Sets the default value inside the input.

<input type="text" value="Hello!">

Output

4. placeholder

Shows a hint to the user inside the input.

<input type="text" placeholder="Enter your name">

Output

5. required

Makes the input mandatory.

<input type="email" required>

Output

6. readonly

Prevents the user from editing the input (but value is submitted).

<input type="text" value="This is fixed" readonly>

Output

7. disabled

Disables the input (value is not submitted).

<input type="text" disabled>

Output

8. maxlength and minlength

Sets character limits for text inputs.

<input type="text" minlength="3" maxlength="10">

Output

9. min and max

Sets numeric or date limits.

<input type="number" min="1" max="100">

Output

10. step

Specifies increments for number/date inputs.

<input type="number" step="5">

Output

11. pattern

Sets a regular expression for validation.

<input type="text" pattern="[A-Za-z]{3,}">

Output

12. autocomplete

Enables or disables browser autofill.

<input type="text" autocomplete="off">

Output

13. autofocus

Automatically focuses the input when the page loads.

<input type="text" autofocus>

Output

14. multiple

Allows multiple file or email selections.

<input type="file" multiple>

Output

15. checked

Sets an input (checkbox or radio) as selected by default.

<input type="checkbox" checked>

Output

16. list

Connects the input to a <datalist> for suggestions.

<input list="browsers">
<datalist id="browsers">
  <option value="Chrome">
  <option value="Firefox">
</datalist>

Output