HTML input elements support a wide range of attributes that allow developers to customize the behavior, appearance, and functionality of form fields. Here’s a comprehensive list of commonly used input attributes and their purposes:
Common HTML Input Attributes
Type:
type : Specifies the type of input (e.g., text , password , email , etc.).
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Name:
name : Defines the name of the input, which is used to reference the data on form submission.
<input type="text" id="text" name="text" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Value:
value : Specifies the default value of the input field.
<input type="text" id="text" name="text" value="Default text" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Placeholder:
placeholder : Displays a short hint that describes the expected value of the input.
<input type="text" id="text" placeholder="Enter your name" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Required:
required : Ensures that the input must be filled before submitting the form.
<input type="text" id="text" name="text" disabled>
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Disabled:
disabled : Disables the input field, preventing user interaction.
<input type="text" id="text" name="text" disabled>
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Readonly:
readonly : Makes the input field read-only, so users cannot change its value.
<input type="text" id="text" value="Cannot change this" readonly>
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Maxlength:
maxlength : Limits the maximum number of characters allowed in the input.
<input type="text" id="text" maxlength="10" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Min and Max:
min and max : Defines the minimum and maximum values for inputs of types like number , range , date , etc.
<input id="number" type="number" min="1" max="100" value="2" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Step:
step : Specifies the increment for numerical inputs.
<input type="number" id="number" step="2" value="2"
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Autocomplete:
autocomplete : Controls whether the browser should auto-fill the input based on previous entries (on or off ).
<input type="text" id="text" name="text" autocomplete="on" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Autofocus:
autofocus : Automatically focuses the input when the page loads.
<input type="text" id="text" autofocus>
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Pattern:
pattern : Defines a regular expression pattern that the input's value must match for validation.
<input type="text" id="text" name="text" pattern="[A-Za-z]{3,}" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Multiple:
multiple : Allows multiple values for inputs of types like email or file .
<input type="email" id="email" name="email" multiple>
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Size:
size : Specifies the visible width (in characters) of the input.
<input type="text" id="text" name="text" size="40" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Minlength:
minlength : Specifies the minimum number of characters required for input.
<input type="text" id="text" name="text" minlength="5" required>
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
List:
list : Connects the input to a <datalist > element to provide predefined options.
<input type="text" list="browsers" >
<datalist id="browsers" >
<option value="Chrome" >
<option value="Firefox" >
<option value="Safari" >
</ datalist >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Accept:
accept : Specifies the file types allowed when using input type="file" .
<input type="file" accept=".jpg,.png,.pdf" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Height and Width:
height and width : Specifies the size of an input type="image" .
<img src="/assets/images/whereisstuff.png" alt="whereisstuff.com" width="100" height="100" >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Novalidate:
novalidate : When added to a form, disables HTML5 form validation.
<form novalidate>
<!-- Text input -->
<label for="text" >Text:</label >
<input type="text" id="text" name="text" ><br ><br >
<!-- Submit button -->
<input type="submit" value="Submit" >
</ form >
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself