HTML Form Tag

  • Purpose: To collect user input from visitors to a website. This input can then be processed and used for various purposes, such as:
    • Signing up for a newsletter
    • Making a purchase
    • Submitting a contact form
    • Logging into an account
  • Tags: <form>
  • Common Form Elements:
    1. <input>: This is the most versatile element, used for various input types:
      • text: For single-line text input (e.g., names, usernames)
      • password: For password input (masked for security)
      • email: For email addresses
      • number: For numerical input
      • date: For date input
      • radio: For selecting one option from a group
      • checkbox: For selecting multiple options from a group
      • file: For uploading files
      • submit: Creates a submit button to send the form data
      • reset: Creates a button to reset the form fields
    2. <textarea>: For multi-line text input (e.g., messages, comments
    3. <select>: For creating dropdown lists or option menus
    4. <option>: Used within <select> to define individual options
    5. <label>: Associates a label with a form control (e.g., a label for a text input field).
  • Example:
<form>
   <label for="name">Name:</label><br>
      <input type="text" id="name" name="name"><br><br>
   <label for="email">Email:</label><br>
      <input type="email" id="email" name="email"><br><br>
      <input type="submit" value="Submit">
</form>

This code creates a simple form with two input fields: one for the user’s name and one for their email address.

Scroll to Top