HTML Forms and Input Overview

HTML Forms and Input

1. Forms (<form>)

The <form> tag is used to create an HTML form for user input. It wraps all the input elements that make up the form.

HTML Example:

<form action="/submit_form" method="post">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name">
    <button type="submit">Submit</button>
</form>

Explanation:

2. Input (<input>)

The <input> tag is used to create various input fields, such as text fields, checkboxes, and radio buttons.

HTML Example:

<input type="text" name="username" placeholder="Enter your name">
<input type="password" name="password" placeholder="Enter your password">
<input type="checkbox" name="subscribe" value="yes"> Subscribe to newsletter
<input type="submit" value="Submit">

Explanation:

3. Text Area (<textarea>)

The <textarea> tag is used to create a multi-line text input field.

HTML Example:

<textarea name="message" rows="4" cols="50">
Enter your message here...
</textarea>

Explanation:

4. Button (<button>)

The <button> tag is used to create clickable buttons.

HTML Example:

<button type="button" onclick="alert('Button clicked!')">Click Me!</button>

Explanation:

5. Select (<select>)

The <select> tag is used to create a drop-down list.

HTML Example:

<select name="cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat">Fiat</option>
    <option value="audi">Audi</option>
</select>

Explanation:

6. Label (<label>)

The <label> tag defines a label for an input element, enhancing accessibility.

HTML Example:

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

Explanation:

7. Fieldset (<fieldset>) and Legend (<legend>)

The <fieldset> tag is used to group related elements in a form, and the <legend> tag defines a caption for the <fieldset>.

HTML Example:

<fieldset>
    <legend>Personal Information</legend>
    <label for="fname">First name:</label>
    <input type="text" id="fname" name="fname"><br>
    <label for="lname">Last name:</label>
    <input type="text" id="lname" name="lname">
</fieldset>

Explanation:

Previous Next
Modern Footer