Free guides, interview Q&As, and job responsibility breakdowns — curated by industry veterans to help you crack MNC interviews
HTML forms are used to collect input from users such as text, email, password, feedback, etc.
The entered data can be sent to a server for processing.
Forms are commonly used for:
A form is created using the <form> tag and contains different form elements like input fields, buttons, and text areas.
<form>
<!-- form elements -->
</form>
The <input> tag is the most important form element.
Its behavior depends on the type attribute.
Used to enter single-line text.
<input type="text" placeholder="Enter text">
Hides the characters entered by the user.
<input type="password" placeholder="Enter password">
Accepts only valid email format.
<input type="email" placeholder="Enter email">
Used for numeric values.
<input type="number">
Used to select only one option from multiple choices.
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female
Used to select multiple options.
<input type="checkbox"> HTML <input type="checkbox"> CSS
Used to submit the form.
<input type="submit" value="Submit">
Used to enter multi-line text such as feedback or messages.
<textarea rows="4" cols="30"></textarea>
Used to create a dropdown list.
<select>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
Another way to create a button.
<button type="submit">Send</button>
| Attribute | Description |
|---|---|
| action | URL where data is sent |
| method | GET or POST |
| required | Makes field mandatory |
| placeholder | Hint text |
<form>
<label>Name:</label><br>
<input type="text" required><br><br><label>Email:</label><br>
<input type="email" required><br><br><label>Message:</label><br>
<textarea rows="4" cols="30"></textarea><br><br><button type="submit">Submit</button>
</form>

Forms are used to collect user data
<input> type defines behavior
POST method is more secure than GET
required ensures validation