# HTML Forms and Inputs

> How a form collects what people type and sends it to a server. The input types, labels and checks that make a form easy to fill in.

**Course:** [HTML, CSS and JavaScript](https://learn.benibix.com/learn/development-web)  
**Time:** 12 min

**After this lesson you can:**

- Build a form with labels and inputs
- Pick the right input type for each field
- Choose GET or POST for a form

## How a form collects data and sends it

An HTML form is the part of a page where people type or pick things to send. It is a <form> element holding fields and a button. The <input> element alone has 22 types, from text and email to date and checkbox. When the button is pressed, the browser sends every field to the server.

Two attributes on the form decide where the data goes. The action attribute names the address that receives it. The method attribute says how it travels. GET puts the fields in the address itself, after a question mark. POST sends them inside the request, out of sight. GET is the default.

Use GET for a search, where the address can be saved and shared. Use POST for anything that changes data, such as an order or a sign-up. A password should never go by GET. The address is kept in the browser's history and in the server's logs.

Each field needs a name attribute, or it is not sent at all. It also needs a label. A <label> with a for attribute that matches the field's id joins the two. Clicking the label then puts the cursor in the box, and a screen reader reads the label out.

The type attribute does a lot of work. On a phone, type="email" brings up a keyboard with an @ key, and type="tel" brings up the number pad. A date field opens a calendar. The browser also checks the shape: an email field will not send without an @ sign.

Add required and the form will not send while that field is empty. Add minlength="8" to a password and anything shorter is turned back. These checks show a message at once, before anything leaves the browser, which saves the user a wait and a wasted trip.

People often treat those checks as the real ones. They are only for comfort. Anyone can skip them by changing the page or sending a request by hand. The server must check every field again before it saves anything.

```html
<form action="/signup" method="post">
  <label for="email">Email</label>
  <input id="email" name="email" type="email" required>

  <label for="pass">Password</label>
  <input id="pass" name="pass" type="password" minlength="8" required>

  <button type="submit">Sign up</button>
</form>
```
Each input has a name, so it is sent, and a label, so people know what it is for.

![A small sign-up form. Each row is one input with its type written beside it: text for the name, email, password with dots, a date box, a range slider, a checkbox, and a Join button of type submit.](https://learn.benibix.com/diagrams/dev5-input-types.svg)

### Example: Emma's sign-up form loses half its users

Emma's form has 9 fields, all plain text boxes with no labels. On phones, 48 of every 100 visitors give up before the end.

She cuts it to 3 fields, adds labels and uses type="email". Phone users now get the right keyboard, and only 20 in 100 give up.

**Words in this lesson:** [HTML Form](https://learn.benibix.com/term/development/html-form), [HTML Input Element](https://learn.benibix.com/term/development/html-input-element), [HTTP Method](https://learn.benibix.com/term/infrastructure/http-method)

**Question:** Which form method should a login page use?

**Answer:** POST, so the password is not put in the address. GET puts the fields in the address, which is saved in history and logs. POST sends them inside the request, so it suits passwords and anything that changes data.

---

Source: https://learn.benibix.com/learn/development-web/html-forms-and-inputs
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
