HTML Form Input | Collecting Data from Users

An HTML form input is an essential component used to collect data from users through forms. It allows users to provide various types of information such as text, numbers, dates, and selections. The <input> tag is the most common element used within forms to define input fields.

Basic Syntax of Form Input:

The <input> tag is used to create different types of form controls, including text boxes, checkboxes, radio buttons, and more. The most common attributes for the <input> tag are:

Using Input Elements in Forms

<form>
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" placeholder="Enter your username">

    <label for="password">Password:</label>
    <input type="password" id="password" name="password" placeholder="Enter your password">

    <input type="submit" value="Submit">
</form>

Example of HTML Form Input:

The following code creates a simple form where the user can input their username and password:

Code Example


    <!DOCTYPE html>
    <html>
    <head>
        <title>HTML Example</title>
    </head>
    <body>
            
    <form action="/submit" method="POST">
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" placeholder="Enter your email">

    <label for="phone">Phone:</label>
    <input type="tel" id="phone" name="phone" placeholder="Enter your phone number">

    <label for="age">Age:</label>
    <input type="number" id="age" name="age" placeholder="Enter your age">

    <input type="submit" value="Submit">
</form>
</body>
</html>

Output

Types of Input Fields:

Features of Input Fields:

Best Practices for Using HTML Input Elements:

HTML input elements are crucial for gathering data from users, and understanding how to use them correctly is key to building functional web forms. By combining proper input types with clear labels and validation, you can create user-friendly forms.