-
Hajipur, Bihar, 844101
An HTML form is used to collect user input. Data entered into form fields is typically sent to a server for processing using the action
and method
attributes.
<form action="/submit" method="post">
<!-- form fields here -->
</form>
Element | Description |
---|---|
<input> |
For text, password, checkbox, radio, etc. |
<textarea> |
Multi-line text input |
<select> |
Dropdown list |
<option> |
Options in a dropdown |
<label> |
Label for form fields |
<button> |
Clickable button |
<fieldset> |
Groups related elements |
<legend> |
Title for a group |
Type | Example |
---|---|
text |
<input type="text"> |
password |
<input type="password"> |
email |
<input type="email"> |
number |
<input type="number"> |
radio |
<input type="radio"> |
checkbox |
<input type="checkbox"> |
submit |
<input type="submit"> |
reset |
<input type="reset"> |
date |
<input type="date"> |
file |
<input type="file"> |
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="username"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="useremail"><br><br>
<label for="msg">Message:</label><br>
<textarea id="msg" name="usermessage" rows="4" cols="30"></textarea><br><br>
<input type="submit" value="Send">
</form>
<label for="email">Email:</label>
<input type="email" id="email" name="useremail">
The for
attribute of <label>
matches the id
of the input field.
<fieldset>
<legend>Personal Info</legend>
<label>Name: <input type="text" name="name"></label>
</fieldset>
Q1. Create a form with name, email, and message fields.
Q2. Add radio buttons for gender selection.
Q3. Use checkboxes for selecting multiple hobbies.
Q4. Implement a dropdown using <select>
and <option>
.
Q5. Add a file upload field using <input type="file">
.
Q6. Use <fieldset>
and <legend>
to group contact fields.
Q7. Create a submit and reset button.
Q8. Make a password input field.
Q9. Add a date of birth field with <input type="date">
.
Q10. Set required attribute for name and email fields.
Q1: Which HTML tag is used to create a form?
Q2: Which attribute defines how form data is sent?
Q3: Which tag is used to create a multi-line text input?
Q4: What input type is used for email addresses?
Q5: Which element groups related form inputs?
Q6: What tag provides options in a dropdown?
Q7: Which input type is best for selecting multiple options?
Q8: What is the default method used if method is not specified?
Q9: What is the purpose of the required attribute?
Q10: What is the purpose of the <label> tag?