Aral Code

Forms Lesson 30 of 42

HTML Forms — Collecting Information from Users

Learn how HTML forms work — the form element, inputs, labels, name, the submit button, and what action and method (GET and POST) mean.

Every time you log in, search on Google, sign up for an account, order food online, or answer a Google Form, you're using an HTML form. Forms are how a website collects information from people. In this lesson you'll learn the parts of a form and build your first one.

A first form

Example A simple sign-up form
<form>
  <label for="fullname">Full name:</label><br>
  <input type="text" id="fullname" name="fullname"><br><br>

  <label for="section">Section:</label><br>
  <input type="text" id="section" name="section"><br><br>

  <button type="submit">Join the Coding Club</button>
</form>

Type something and press the button. (In this practice editor, the form doesn't really send anything — you'll see a "submitted" message instead.)

The parts of a form

form — the container

<form> wraps all the fields that are sent together. When the user submits, the browser collects the data from every field inside it.

input — the field

<input> is the most common form field. Its type attribute decides what kind: text, email, password, number, date, checkbox, and more. It's an empty element — no closing tag. You'll see all the types in the next lesson.

label — the caption

<label> is the text that tells users what to type. Connect it to its input by making the label's for match the input's id.

button — to submit

<button type="submit"> sends the form. You can also use <input type="submit" value="Send">, which does the same thing.

Why labels matter so much

A label connected with for and id does two big things:

  • Bigger tap area. Clicking the label puts the cursor in the field, or checks the checkbox. On phones, this makes forms much easier to use.
  • Accessibility. Screen readers announce the label when the user enters the field. Without it, a blind user hears just "edit text" and has no idea what to type.
Example Tap the label text, not the box
<input type="checkbox" id="agree" name="agree">
<label for="agree">I agree to follow the computer lab rules.</label>

You can also wrap the input inside the label, which connects them without for and id:

<label>
  <input type="checkbox" name="newsletter"> Send me updates
</label>

The name attribute

When a form is sent, each value is paired with its field's name. If an input has no name, its value is not sent at all. For the sign-up form above, the server would receive something like:

fullname=Juan Dela Cruz
section=10-Rizal

Think of name as the label on an envelope: the server uses it to know which piece of information is which.

action and method: where and how the data goes

<form action="/register" method="post">
  ...
</form>
  • action — the address that receives the data (usually a program on the server).
  • method — how to send it:
    • get puts the data in the address bar, like search?q=adobo. Good for searches, since the results page can be bookmarked or shared.
    • post sends the data hidden inside the request. Use it for logins, sign-ups, and anything private or that changes something.
Example A search form using GET
<form action="https://www.google.com/search" method="get" target="_blank">
  <label for="q">Search Google:</label>
  <input type="search" id="q" name="q" placeholder="e.g. Philippine eagle">
  <button type="submit">Search</button>
</form>

That really works — Google's search page reads the q value from the address. (In this practice editor, the submit is caught, so you'll see a message instead. Try the same code in your own file.)

Grouping fields with fieldset

For longer forms, group related fields with <fieldset> and give the group a title with <legend>:

Example fieldset and legend
<form>
  <fieldset>
    <legend>Student Information</legend>
    <label for="lrn">LRN:</label>
    <input type="text" id="lrn" name="lrn"><br><br>
    <label for="grade">Grade level:</label>
    <input type="number" id="grade" name="grade" min="7" max="12">
  </fieldset>
  <br>
  <button type="submit">Submit</button>
</form>

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Which element wraps all the fields that are submitted together?
2. How do you connect <label> to <input id="email">?
3. What happens to an input's value if the input has no name?
4. Which method is best for a login form?

By Sir Reyel · Last updated 2026-12-04