HTML Foundations

Lesson 4 of 6

Building Forms

Forms are how HTML collects input from a visitor: search boxes, login screens, checkout pages.

A basic form

HTML
  • action is the URL the data is sent to; method is usually GET (data in the URL, for searches/filters) or POST (data in the request body, for anything that changes data).
  • Every <input> needs a matching <label>, connected by for on the label and id on the input. This isn't cosmetic, screen reader users rely on it, and it lets sighted users click the label text to focus the field.

Input types matter

HTML

Each type changes both the on-screen keyboard/widget shown (especially on mobile) and what the browser validates automatically, type="email" alone gives you free client-side validation for a well-formed address.

WARNING

Client-side form validation (like required or type="email") improves the experience, but it is never a substitute for validating input on the server. Anyone can bypass it entirely by sending a request directly.

📝 Forms Quiz

Passing score: 70%
  1. 1.How do you connect a <label> to its <input> for accessibility?

  2. 2.Client-side validation like the "required" attribute means you no longer need to validate on the server.

  3. 3.The form attribute that controls where submitted data is sent is ____.