HTML INPUT ATTRIBUTES

Maha

HTML Input Attributes

HTML input attributes are various properties that you can set to control the behavior and appearance of <input> elements in HTML forms.

Common attributes :

1. type

Specifies the type of input element.

Example:

<input type="text" name="username">
<input type="password" name="password">
<input type="email" name="email">


2. name

Specifies the name of the input element, which is used to reference form data after it’s submitted.

Example:

<input type="text" name="username">


3. value

Specifies the initial value of the input element.

Example:

<input type="text" name="username" value="JohnDoe">


4. placeholder

Provides a hint to the user of what can be entered in the input field.


Example:

<input type="text" name="username" placeholder="Enter your username">


5. required

Specifies that the input field must be filled out before submitting the form.

Example:

<input type="text" name="username" required>


6. readonly

Specifies that the input field is read-only.

Example:

<input type="text" name="username" value="JohnDoe" readonly>


7. disabled

Specifies that the input field is disabled.

Example:

<input type="text" name="username" value="JohnDoe" disabled>


8. maxlength

Specifies the maximum number of characters allowed in the input field.

Example:

<input type="text" name="username" maxlength="10">


9. size

Specifies the width of the input field (in characters).

Example:

<input type="text" name="username" size="20">


10. min and max

Specifies the minimum and maximum values for an input field.

Example:

<input type="number" name="age" min="18" max="99">


11. step

Specifies the interval between legal numbers in an input field.

Example:

<input type="number" name="quantity" step="5">


12. pattern

Specifies a regular expression that the input field’s value must match.

Example:

<input type="text" name="username" pattern="[A-Za-z]{3,}">


13. autofocus

Specifies that the input field should automatically get focus when the page loads.

Example:

<input type="text" name="username" autofocus>


14. autocomplete

Specifies whether the input field should have autocomplete enabled.

Example:

<input type="text" name="username" autocomplete="off">


15. multiple

Specifies that the user can enter more than one value (for <input type="file"> or <input type="email">).

Example:

<input type="file" name="files" multiple> 
<input type="email" name="emails" multiple>


16. list

Refers to a <datalist> element that contains predefined options for the input field.


Example:

<input type="text" name="browsers" list="browsers-list"> 
<datalist id="browsers-list"> 
  <option value="Chrome"> 
  <option value="Firefox"> 
  <option value="Safari"> 
</datalist>
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send