HTML & CSS Course
HTML & CSS
/
Beginner

HTML Forms

Definition

The `<form>` element is used to collect user input. It acts as a container for interactive controls (like text fields, checkboxes, and buttons) to submit data to a web server.

Explain Like I'm New

A form is a digital envelope. You put inputs (fields) inside the envelope. The user fills them out. When they click the Submit button, the browser seals the envelope and sends it to the URL specified in the `action` attribute.

Real World Example

The Login screen of every website. It is a `<form>` containing an email input, a password input, and a submit button.

Common Use Cases

  • •User registration/login
  • •Checkout processes
  • •Search bars

Interactive Example

Interview Questions

basic

  • What does the `action` attribute do on a `<form>` tag?

intermediate

  • What is the difference between `method="GET"` and `method="POST"`?

Flash Cards

Question

What does action do?

Click to reveal answer
Answer

It defines the URL where the form data will be sent when the user clicks submit.

Question

GET vs POST?

Click to reveal answer
Answer

`GET` takes the form data and appends it to the URL (e.g., `google.com/search?q=cats`). It is used for searching. `POST` hides the data in the HTTP request body. It is used for sensitive data (like sending a password) or creating new data in a database.