HTML Form elements

HTML form elements are used to collect user input. Here are some of the most commonly used form elements:

1. Form (<form>):

The container for all form elements.


<form action="/submit" method="post">
    <!-- form elements go here -->
</form>

2. Input (<input>): Used for various types of user input.


<!-- Text input -->
<input type="text" name="username">

<!-- Password input -->
<input type="password" name="password">

<!-- Checkbox input -->
<input type="checkbox" name="remember_me">

<!-- Radio button input -->
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female

<!-- Submit button -->
<input type="submit" value="Submit">

3. Label (<label>): Used to define labels for input elements.


<label for="username">Username:</label>
<input type="text" id="username" name="username">

4. TextArea (<textarea>): Multi-line text input.


<textarea name="message" rows="4" cols="50"></textarea>

5. Select (<select>): Dropdown list.


<select name="options">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3">Option 3</option>
</select>

6. Button (<button>): Button element.


<button type="submit">Submit</button>

7. Fieldset (<fieldset>) and Legend (<legend>): Used to group related elements and provide a caption.


<fieldset>
    <legend>Personal Information</legend>
    <label for="firstname">First name:</label>
    <input type="text" id="firstname" name="firstname">
    <label for="lastname">Last name:</label>
    <input type="text" id="lastname" name="lastname">
</fieldset>

8. Datalist (<datalist>): Provides a list of predefined options for an input element.


<input list="browsers" name="browser">
<datalist id="browsers">
    <option value="Chrome">
    <option value="Firefox">
    <option value="Safari">
    <option value="Edge">
    <option value="Opera">
</datalist>

9. Output (<output>): Represents the result of a calculation or user action.


<output name="result" for="a b">0</output>

10. Input types: There are many other types of input elements, such as color, date, email, file, number, range, search, tel, time, url, etc.


<!-- Date input -->
<input type="date" name="birthday">

<!-- Email input -->
<input type="email" name="email">

<!-- Number input -->
<input type="number" name="quantity" min="1" max="10">