HTML input elements have several attributes that can be used to define their behavior and appearance. Some common input attributes include:
- type: Specifies the type of input element, such as text, password, checkbox, radio, number, email, date, etc. Example:
<input type="text">
- name: Specifies the name of the input element, which is used when submitting the form data to the server. Example:
<input type="text" name="username">
- value: Specifies the initial value of the input element. Example:
<input type="text" name="username" value="John Doe">
- placeholder: Specifies a short hint that describes the expected value of the input element. Example:
<input type="text" name="email" placeholder="Enter your email">
- required: Specifies that the input element must be filled out before submitting the form. Example:
<input type="email" name="email" required>
- readonly: Specifies that the input element is read-only and cannot be modified by the user. Example:
<input type="text" name="username" value="John Doe" readonly>
- disabled: Specifies that the input element is disabled and cannot be used by the user. Example:
<input type="text" name="username" value="John Doe" disabled>
- size: Specifies the width of the input element in characters. Example:
<input type="text" name="username" size="30">
- maxlength: Specifies the maximum number of characters that can be entered into the input element. Example:
<input type="text" name="username" maxlength="20">
- min and max: Specifies the minimum and maximum values that can be entered into the input element. Example:
<input type="number" name="age" min="18" max="100">
- step: Specifies the increment by which the input value will be increased or decreased when the user interacts with the input element. Example:
<input type="number" name="quantity" step="1">
- multiple: Specifies that multiple values can be entered into the input element (for file uploads or select boxes). Example:
<input type="file" name="files" multiple>
These are just some of the attributes that can be used with HTML input elements. Other input attributes include autofocus, autocomplete, form, formaction, formenctype, formmethod, formnovalidate, formtarget, list, pattern, etc.