5 Essential Input Form Attributes in HTML
A Simple Guide to Exploring Input Attributes in HTML Forms
Introduction
HTML input attributes are an essential part of web development when creating forms. HTML provides a wide range of input attributes to create interactive and dynamic web pages. They are used to specify additional information about an input element.
Let's check out 5 of the most commonly used input attributes available for HTML forms:
🧨Readonly Attribute
The input readonly
attribute specifies that an input field cannot be edited by the user.
A read-only input field cannot be edited by the user. However, it can be viewed, highlighted, or copied.
The value of a read-only input field, although cannot be modified, will be sent when submitting the form!
In this example, the readonly
attribute is used with a text input field that that displays an Account ID and prevents the user from modifying it.
🧨Disabled Attribute
The input disabled
attribute specifies that an input field is disabled and cannot be used.
A disabled input field is un-clickable and is commonly used to prevent users from interacting with a form field
The value of a disabled input field will not be submitted with the form!
In the above example, users can only choose between the iPhone 11, 12, 13, and 14 models from the dropdown menu. The iPhone 7, iPhone 8, and iPhone 10 options are also included, but they are disabled using the disabled
attribute. The selected
attribute is used to select the iPhone 13 model by default.
🧨Maxlength Attribute
The input maxlength
attribute specifies the maximum number of characters that can be entered in an input field.
It contains a single value number and the input field will not accept more than the specified number of characters.
Here, we set the maxlength
attribute of the PIN to be 7 so the user can enter a zip code containing a maximum of 7 digits in the input field.
🧨Placeholder Attribute
The input placeholder
attribute specifies a short hint/prompt that describes the expected value of the input field (a sample value or a short description of the expected format).
The placeholder text is displayed in the input field until the user begins typing.
The placeholder
attribute works with input types such as text, search, URL, tel, email, and password.
In the above example, the placeholder
attribute provides an example of the expected format of the phone number, making it easier for users to enter their information correctly.
🧨Required Attribute
The input required
attribute specifies that the input field must be filled out before the form can be submitted.
If the user tries to submit the form without filling out the required field, an error message will be displayed.
The required
attribute works with the following input types: text, search, URL, tel, email, password, date pickers, number, checkbox, radio, and file.
When making an online purchase, the user may be required to provide their billing and shipping information. The required
attribute is applied to the name
, city
, state
, and zip code
input fields indicating that these fields must be filled out before the purchase can be completed.
In Short
HTML input attributes provide a wide range of options to customize input elements in a web page. By using these essential input form attributes in HTML, you can create forms that are informative, easy to use, and enhance the overall user experience.
Overall, understanding these attributes and how to use them effectively are essential in ensuring the accuracy and completeness of the form data.
References
Thank you for taking the time to read this blog. I hope you found it informative and enjoyable!
Catch you guys on the next one. Cheers .. ✌️