Course contentsShow
← Web Development
Lesson 91 of 2,9822. HTML FundamentalsFree lesson

The <form> Element and Form Submission

Understanding the form element, its action and method attributes, and how forms submit data to servers.

The <form> Element and Form Submission

What you'll learn: How HTML forms collect user input and send it to a server for processing.

What is a Form?

Think of an HTML <form> like a paper form at a doctor's office. You fill in your information in various fields, then submit it to the receptionist who processes it. In web development, the <form> element is the container that groups input fields together and handles sending that data to a server when submitted.

The Core Attributes

Every form needs to know where to send the data and how to send it:

<form action="/submit-contact" method="POST">
  <!-- form inputs go here -->
</form>
  • action: The URL (destination) where the form data will be sent—like the address on an envelope
  • method: The HTTP method to use, typically GET or POST (remember these from earlier lessons!)

How Form Submission Works

When a user clicks a submit button, the browser packages up all the form data and sends an HTTP request to the server specified in the action attribute, using the method you chose. The server then processes this data and typically sends back a response (like a confirmation page).

Use POST when submitting data that changes something (like creating an account). Use GET for searches or filtering, where data appears in the URL.

Example Structure

<form action="/register" method="POST">
  <label>Name: <input type="text" name="username"></label>
  <button type="submit">Sign Up</button>
</form>

Key Takeaway: The <form> element wraps inputs and uses its action attribute to specify where data goes and method to specify how it's sent (GET or POST).