The <input>
element is used in HTML forms to create interactive controls for user input. It is one of the most common form elements and can be used for a wide variety of input types such as text, numbers, dates, checkboxes, and more.
The <input>
element is used when you need to collect data from the user, such as a name, email, or password. It is often used within a <form>
element to create form fields.
The <input>
element has various types to control the behavior of the input field. The type is specified using the type
attribute. Some common input types are:
text
- Defines a single-line text field.password
- Hides the text entered by the user (used for passwords).email
- Validates an email address.number
- Allows numeric input only.checkbox
- Creates a checkbox.radio
- Creates a radio button for selecting options.date
- Provides a date picker.<input type="type" name="name" value="value">
<!DOCTYPE html> <html> <head> <title>Input Example</title> </head> <body> <form> <label for="name">Name:</label> <input type="text" id="name" name="name"> <br> <label for="email">Email:</label> <input type="email" id="email" name="email"> <br> <label for="password">Password:</label> <input type="password" id="password" name="password"> <br> <input type="submit" value="Submit"> </form> </body> </html>
email
for email addresses, password
for passwords).label
tags to associate text labels with input fields for better accessibility.required
attribute to make certain fields mandatory.type
attribute for validation wherever possible (e.g., type="email"
for email validation).The <input>
element is a versatile and essential part of HTML forms. By choosing the correct type
for your input fields, you can create more user-friendly and accessible forms.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!