HTML Input Attributes
This chapter describes the different attributes for the HTML <input> element.
The value Attribute
The value attribute specifies the initial value for an input field.
<input type="text" value="John Doe">The readonly Attribute
The readonly attribute specifies that an input field is read-only (cannot be changed).
Example
<label for="country">Country:</label><br>
<input type="text" id="country" name="country" value="Norway" readonly>The disabled Attribute
The disabled attribute specifies that an input field should be disabled. A disabled input field is unusable and un-clickable, and its value will not be sent when submitting the form.
Example
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John" disabled>The maxlength Attribute
The maxlength attribute specifies the maximum number of characters allowed in an input field.
Example
<label for="pin">PIN:</label><br>
<input type="text" id="pin" name="pin" maxlength="4" size="4">The min and max Attributes
The min and max attributes specify the minimum and maximum values for an input element with a numeric or date type.
Example
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">The required Attribute
The required attribute is a boolean attribute that specifies that an input field must be filled out before submitting the form.
Example
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>The placeholder Attribute
The placeholder attribute specifies a short hint that describes the expected value of an input field (a sample value or a short description of the format).
<input type="text" placeholder="Enter your name">Test Yourself with an Exercise
Which attribute specifies that an input field must be filled out?