Input Attributes in HTML
? Input Attributes in HTML
The <input> element is used for interactive controls in forms, and it supports many attributes to control its behavior.
Common Attributes of <input>
| Attribute | Description | Example |
|---|---|---|
type | Defines the kind of input (text, password, email, etc.) | <input type="email"> |
name | Name of the input, sent with form data | <input name="username"> |
value | Default or current value | <input value="Hello"> |
placeholder | Hint text shown when input is empty | <input placeholder="Enter email"> |
id | Unique identifier | <input id="email"> |
required | Makes input mandatory | <input required> |
readonly | Input cannot be edited | <input readonly> |
disabled | Input is disabled, not interactive | <input disabled> |
maxlength | Maximum number of characters | <input maxlength="10"> |
min / max | Minimum and maximum values (for number, date, etc.) | <input type="number" min="1" max="10"> |
step | Increment step for number input | <input type="number" step="0.5"> |
autocomplete | Enable/disable browser autocomplete | <input autocomplete="off"> |
pattern | Regex pattern to validate input | <input pattern="[A-Za-z]{3}"> |
Example
<form> <input type="text" name="username" placeholder="Enter username" required> <input type="password" name="password" required minlength="6"> <input type="email" name="email" placeholder="you@example.com"> <input type="submit" value="Register"></form>Want a detailed example for each input type or how to validate inputs with patterns?