HTML Input Form Attribute
HTML input elements have various attributes that help control the input's
behavior, appearance, and the data it collects. Here are some commonly used
input attributes with their definitions and examples:
1. type
Specifies the type of input element to display.Example:
<input type="password" name="password">
<input
type="submit"
value="Submit">
2. name
Specifies the name of the input element. The name attribute is used
to reference form data after it is submitted.
Example:
<input type="text" name="firstname">
3. value
Specifies the initial value of the input element.
Example:
<input type="text" name="firstname" value="John">
4. placeholder
Specifies a short hint that describes the expected value of the input
field (a sample value or a short description of the format).
Example:
<input type="text" name="username" placeholder="Enter your username">
5. required
Indicates that the input field must be filled out before submitting
the form.
Example:
<input type="text" name="firstname" required>
6. readonly
Specifies that the input field is read-only.Example:
<input type="text" name="firstname" value="John" readonly>
7. disabled
Specifies that the input field is disabled (not editable and not submitted).Example:
<input
type="text"
name="firstname"
value="John"
disabled>
8. maxlength
Specifies the maximum number of characters allowed in the input
field.
Example:
<input
type="text"
name="username"
maxlength="10">
9. minlength
Specifies the minimum number of characters required in the input field.Example:
<input
type="text"
name="username"
minlength="5">
10. size
Specifies the visible width, in characters, of the input element.Example:
<input type="text" name="username" size="20">
11. pattern
Specifies a regular expression that the input element's value is checked against.Example:
<input type="text" name="username" pattern="[A-Za-z]{3,}">
12. autofocus
Specifies that the input field should automatically get focus when the page loads.Example:
<input type="text" name="username" autofocus>
13. autocomplete
Specifies whether the input field should have autocomplete enabled. Common values areon
and
off
.Example:
<input type="text" name="username" autocomplete="on">
14. step
Specifies the legal number intervals for an input field. It is often used withtype="number"
or
type="date"
.Example:
<input type="number" name="age" step="1">
15. min and max
Specifies the minimum and maximum values for an input field.Example:
<input type="number" name="age" min="18" max="99">
16. multiple
Specifies that the user is allowed to enter more than one value in the input field. It is often used withtype="file"
or
type="email"
.Example:
<input type="file" name="files" multiple>
17. accept
Specifies the types of files that the server accepts (that can be submitted through a file upload).Example:
<input type="file" name="resume" accept=".pdf, .doc">
18. list
Refers to a<datalist>
element that contains predefined options for the input.Example:
<input type="text" name="browser" list="browsers">
<datalist
id="browsers">
<option
value="Chrome">
<option
value="Firefox">
<option
value="Safari">
<option
value="Edge">
</datalist>
19. formnovalidate
Specifies that the form should not be validated when submitted
(only applicable for buttons of type="submit").
Example:
<input type="submit" value="Submit" formnovalidate>
20. formtarget
Specifies where to open the form response after submission (only
applicable for buttons of type="submit").
Values: _self, _blank, _parent, _top, or a named iframe
Example:
<input type="submit" value="Submit"
formtarget="_blank">
More topic in HTML