An HTML form is used to collect user input. The data entered by users can be sent to a server for processing.
An HTML form is a section of a webpage that allows users to enter information.
Forms are commonly used for:
The <form> element creates an HTML form.
<form> ... </form>
The form tag acts as a container for form controls.
The input element is the most commonly used form element.
<input type="text">
Different input types can be used for different purposes.
| Type | Purpose |
|---|---|
| text | Text Input |
| password | Password |
| radio | Single Choice |
| checkbox | Multiple Choices |
| submit | Submit Form |
| button | Button |
| file | Upload File |
<form action="save.php" method="post"> ... </form>
HTML provides many form controls for collecting user data.
Textarea is used for entering large amounts of text.
<textarea rows="4" cols="30"> </textarea>
Select creates a drop-down list.
<select> <option>India</option> <option>Nepal</option> </select>
Fieldset groups related form elements. Legend provides a caption.
<fieldset> <legend> Student Details </legend> ... </fieldset>
Validation helps users enter correct information.
<input type="text" required placeholder="Name">
<form> Name: <input type="text"> <br><br> Email: <input type="email"> <br><br> Password: <input type="password"> <br><br> <input type="submit"> </form>
Which HTML element is used to create a form?