HTML Form

HTML forms are used to collect user input. They are essential for tasks such as user registration, login, and submitting information. A form can include various input elements like text fields, radio buttons, checkboxes, and more.

HTML input element

The HTML <input> element is a versatile and essential part of web forms, allowing users to enter data in various formats. Different types of <input> elements can be used to capture a wide range of user input, from text and numbers to dates and files. Each type of input can have specific attributes to customize its behavior.

Text input


 <form>
	<!-- Text Input -->
	<label for="username">Username:</label><br>
	<input type="text" id="username" name="username" placeholder="Enter your username">
</form>

Password Input


 <form>
	 <label for="password">Password:</label><br>
     <input type="password" id="password" name="password" minlength="6">
</form>


Email Input


 <form>
	    <label for="email">Email:</label><br>
        <input type="email" id="email" name="email">
</form>

Radio Buttons


 <form>
  <label>Gender:</label><br>
        <input type="radio" id="male" name="gender" value="male" checked>
        <label for="male">Male</label><br>
        <input type="radio" id="female" name="gender" value="female">
        <label for="female">Female</label>
</form>


Checkboxes


<form>
<label>Hobbies:</label><br>
        <input type="checkbox" id="hobby1" name="hobbies" value="reading">
        <label for="hobby1">Reading</label><br>
        <input type="checkbox" id="hobby2" name="hobbies" value="traveling">
        <label for="hobby2">Traveling</label><br>
        <input type="checkbox" id="hobby3" name="hobbies" value="gaming">
        <label for="hobby3">Gaming</label>
</form>



Dropdown Select


<form>
 <label for="country">Country:</label><br>
        <select id="country" name="country">
            <option value="in">India</option>
            <option value="us">Unites States</option>
            <option value="uk">United Kingdom</option>
            <option value="au">Australia</option>
        </select>
</form>

File Upload


<form>
<label for="resume">Upload Resume:</label><br>
<input type="file" id="resume" name="resume" accept=".pdf,.doc,.docx">
</form>

Number Input


<form>
<label for="age">Age:</label><br>
<input type="number" id="age" name="age" min="18" max="100">
</form>

Date Input


<form>
<label for="dob">Date of Birth:</label><br>
<input type="date" id="dob" name="dob">
</form>

HTML Form – Interview Questions

Q 1: What is an HTML form?
Ans: A form is used to collect user input.
Q 2: Which tag is used to create a form?
Ans: tag.
Q 3: What happens when a form is submitted?
Ans: The data is sent to a server.
Q 4: Which method sends data securely?
Ans: POST method.
Q 5: Can forms work without a backend?
Ans: Yes, using JavaScript.

HTML Form – Objective Questions (MCQs)

Q1. Which tag is used to create a form in HTML?






Q2. What is the main purpose of an HTML form?






Q3. Which attribute specifies where to send the form data?






Q4. Which attribute defines how form data is sent to the server?






Q5. Can forms contain other elements like text fields, checkboxes, and buttons?






Related HTML Form Topics