#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
5 min read
•Question 9 of 49easy

How do HTML Forms Work?

Collecting user input on the web.

What You'll Learn

  • How forms collect and submit data
  • GET vs POST methods
  • Form controls and elements

Understanding HTML Forms

HTML forms collect user input and send it to a server for processing. The <form> element wraps input fields and defines where and how data is sent.

Key Attributes

  • action - URL where data is sent
  • method - HTTP method (GET or POST)

GET vs POST

MethodData LocationUse Case
GETVisible in URLSearch, filters
POSTHidden in bodyLogin, signup

Form Controls

index.htmlHTML
<form action="/submit" method="POST">
  <!-- Text inputs -->
  <label for="name">Name:</label>
  <input type="text" id="name" name="name" required>

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

  <!-- Textarea -->
  <label for="message">Message:</label>
  <textarea id="message" name="message" rows="4"></textarea>

  <!-- Select dropdown -->
  <label for="country">Country:</label>
  <select id="country" name="country">
    <option value="us">United States</option>
    <option value="uk">United Kingdom</option>
  </select>

  <!-- Checkbox and Radio -->
  <input type="checkbox" id="subscribe" name="subscribe">
  <label for="subscribe">Subscribe</label>

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

Important

The name attribute is crucial - it becomes the key in submitted data.