HTML INPUT FORM ATTRIBUTE

Maha



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:


Commonly Input Form Attribute:

1. type

Specifies the type of input element to display.

Syntax:

<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.

Syntax:

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

3. value

Specifies the initial value of the input element.

Syntax:

<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).

Syntax:

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

5. required

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

Syntax:

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

6. readonly

Specifies that the input field is read-only.

Syntax:

<input type="text" name="firstname" value="John" readonly>

7. disabled

Specifies that the input field is disabled (not editable and not submitted).

Syntax:

<input type="text" name="firstname" value="John" disabled>

8. maxlength

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

Syntax:

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

9. minlength

Specifies the minimum number of characters required in the input field.

Syntax:

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

10. size

Specifies the visible width, in characters, of the input element.

Syntax:

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

11. pattern

Specifies a regular expression that the input element's value is checked against.

Syntax:

<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.

Syntax:

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

13. autocomplete

Specifies whether the input field should have autocomplete enabled. Common values are on and off.

Syntax:

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

14. step

Specifies the legal number intervals for an input field. It is often used with type="number" or type="date".

Syntax:

<input type="number" name="age" step="1">

15. min and max

Specifies the minimum and maximum values for an input field.

Syntax:

<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 with type="file" or type="email".

Syntax:

<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).

Syntax:

<input type="file" name="resume" accept=".pdf, .doc">

18. list

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

Syntax:

<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").

Syntax:

<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

Syntax:

<input type="submit" value="Submit" formtarget="_blank">





More topic in HTML

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send