Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 3

Native Form Controls Done Right

Build forms from the controls the browser already provides, label them properly, group related fields and let the right types and autocomplete tokens do quiet work for your users.

Contentsand lesson path

What you will learn

  • Build forms from native controls with visible labels, grouped fields, correct input types and autocomplete tokens, fully usable with a keyboard.

Prerequisites: React Components & State

01. Why it matters

Forms are how the web does business. Signing up, checking out, commenting, paying: every one of these is a form, and the quality of those forms decides whether people finish or give up. The browser already ships an enormous amount of machinery for this: keyboard support, screen reader announcements, autofill, on-screen keyboards shaped to the field, and validation. All of it is attached to the native controls — input, select, textarea, button — and all of it is lost the moment you rebuild a widget out of divs.

That loss is rarely intentional. A control gets restyled for the design system, then made clickable with JavaScript, and quietly stops being a form control. This lesson shows what the native controls give you when you keep them, and the small amount of markup — visible labels, grouping, correct types, autocomplete tokens — that turns them into a form every person and every browser can use. Later lessons in this skill build validation and submission on exactly this foundation, so the markup you write here keeps paying off.

02. Labels give every field a name

The single most important rule of form markup is that every field has a visible <label>, connected to it. The connection can go two ways: put the control inside the label, or point a for attribute at the control's id. Explicit for/id is the more common style in component libraries because the label and the field can sit anywhere in the markup.

That connection does three jobs at once. Clicking the label focuses or toggles the field, which matters most for small targets such as checkboxes and radios. Screen readers announce the label as the field's accessible name when the user reaches it. And the same name is what automation, tests and the browser's own logic see. A placeholder is not a label: it disappears as soon as typing starts, is often too low-contrast, and is only ever a fallback name. A hint such as "At least 8 characters" is not the name either — it is extra description, and it gets associated separately with aria-describedby, which the next lesson uses for errors.

HTML · signup.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Create your account - Workshop Notes</title>
  </head>
  <body>
    <h1>Create your account</h1>
    <form action="/signup" method="post">
      <label for="fullname">Full name</label>
      <input id="fullname" name="fullname" type="text"
             autocomplete="name" required>

      <label for="email">Email</label>
      <input id="email" name="email" type="email"
             autocomplete="email" required>

      <label for="password">Password</label>
      <input id="password" name="password" type="password"
             autocomplete="new-password" required minlength="8"
             aria-describedby="password-hint">
      <p id="password-hint">At least 8 characters.</p>

      <fieldset>
        <legend>Account type</legend>
        <input id="role-personal" type="radio" name="role"
               value="personal" checked>
        <label for="role-personal">Personal</label>
        <input id="role-team" type="radio" name="role" value="team">
        <label for="role-team">Team</label>
      </fieldset>

      <label for="country">Country</label>
      <select id="country" name="country" autocomplete="country-name">
        <option value="">Choose…</option>
        <option value="vn">Vietnam</option>
        <option value="de">Germany</option>
        <option value="jp">Japan</option>
      </select>

      <input id="terms" name="terms" type="checkbox" required>
      <label for="terms">I agree to the terms of service</label>

      <button type="submit">Create account</button>
    </form>
  </body>
</html>
JavaScript · a11y-check.mjs (Playwright 1.64, Chromium 156)
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
const { chromium } = createRequire(process.cwd() + '/package.json')
  ('@playwright/test');
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(pathToFileURL('signup.html').href);
const fields = await page.$$eval(
  'form input, form select, form button',
  (els) =>
    els.map((el) => ({
      tag: el.tagName.toLowerCase(),
      type: el.getAttribute('type') ?? '',
      name: el.getAttribute('name') ?? '',
      accName: el.labels?.[0]?.textContent.trim() ?? '(none)',
    })),
);
console.log('Accessible names:');
for (const f of fields) {
  console.log(`  ${f.tag}${f.type ? `[type=${f.type}]` : ''} name=${f.name}` +
    ` -> "${f.accName}"`);
}
console.log(await page.locator('form').ariaSnapshot());
await browser.close();
Expected output
Accessible names:
  input[type=text] name=fullname -> "Full name"
  input[type=email] name=email -> "Email"
  input[type=password] name=password -> "Password"
  input[type=radio] name=role -> "Personal"
  input[type=radio] name=role -> "Team"
  select name=country -> "Country"
  input[type=checkbox] name=terms -> "I agree to the terms of service"
  button[type=submit] name= -> "(none)"
- text: Full name
- textbox "Full name"
- text: Email
- textbox "Email"
- text: Password
- textbox "Password"
- paragraph: At least 8 characters.
- group "Account type":
  - text: Account type
  - radio "Personal" [checked]
  - text: Personal
  - radio "Team"
  - text: Team
- text: Country
- combobox "Country":
  - option "Choose…" [selected]
  - option "Vietnam"
  - option "Germany"
  - option "Japan"
- checkbox "I agree to the terms of service"
- text: I agree to the terms of service
- button "Create account"

Read the accessibility tree from the bottom half of that output: it is what a screen reader user actually experiences. Every control carries its label as a name, the radio buttons sit inside a named group, and the checkbox is announced with the whole sentence it agrees to. The button shows (none) in the first list only because a <button> takes its name from its own text content rather than from a label element — in the tree it is button "Create account", exactly as intended.

03. Group related fields, choose real controls

A fieldset wraps related controls and its legend names the group. The classic case is the radio group in the form above: without the legend, a screen reader user tabbing to "Team" hears a radio called Team — but not what is being chosen. With the legend, the announcement is effectively "Account type, radio, Team". The same pattern fits address blocks ("Shipping address") and any question whose options do not repeat the question in their own labels.

Choosing the control itself is a design decision with an accessibility budget attached. A fixed list of any size belongs in a select: it submits one value, works with arrow keys, and mobile browsers open a purpose-built picker. Radio buttons earn their place when there are two to seven options and seeing all of them helps. Checkboxes are for independent yes/no answers, never for mutually exclusive choices — three checkboxes where exactly one may be ticked is a bug waiting for the user. And a submit action belongs on a real <button type="submit">: it fires the form's submission with Enter or Space, is focusable, and is announced as a button. A div with a click handler does none of that, no matter how convincing the CSS.

04. Types, autocomplete tokens and the name attribute

The type attribute picks the control's behaviour. type="email" brings an @ key on phone keyboards and lets the browser check the format; type="password" hides the text and lets password managers offer generation; type="date" opens a calendar instead of hoping the user guesses an accepted format. Types are also how you avoid misuse: a card number, a postcode or an IBAN are identifiers, not numbers you do arithmetic on, so they belong in a plain text field with inputmode="numeric" rather than in type="number" with its spinners and dropped leading zeros.

The autocomplete attribute is what lets the browser fill the field for the user. It takes standard tokens defined in the HTML standard — name, email, new-password, country-name, address-line1, cc-number and many more. When the token matches what the user's browser or password manager has saved, the field fills itself, and mobile browsers surface the right suggestion. Made-up values such as autocomplete="user-mail" do nothing.

Finally, the name attribute is the key under which the field is submitted. The server never sees your id or your label; it sees name=value pairs. A field without a name is invisible to submission, which is a classic cause of "the field is right there on screen but the server gets nothing".

One row per field of signup.html
Field      Type        Autocomplete   Submitted as
Full name  text        name           fullname=<value>
Email      email       email          email=<value>
Password   password    new-password   password=<value>
Account    radio       (none)         role=personal | role=team
Country    select      country-name   country=vn | country=de | ...
Terms      checkbox    (none)         terms=on (only when ticked)

05. Check your understanding

Practice check · 3 questions

Choosing and wiring native controls

Three decisions from the signup form above.

Q1. A booking form must ask for the traveller's country from a fixed list of about 200 options. Which native control fits best?
Q2. A teammate wants to rebuild the country select as a div-based dropdown so it can match the design pixel for pixel. What is the strongest reason to keep the native select?
Q3. After a refactor, the email field still shows its label, but the server receives no email value. The markup is <input id="email" type="email">. What is missing?
Practice only: not graded, not saved, not evidence.

06. Apply it

Take a form you have built, or rebuild signup.html from this lesson, and audit it:

  1. List every field and write down its accessible name. If any name comes from a placeholder or from nothing, give the field a visible label.
  2. Check every autocomplete attribute against the standard token list, and add the tokens that are missing.
  3. Find any grouped question and wrap it in a fieldset with a legend that reads as a question.
  4. Tab through the whole form with only the keyboard and note where focus goes; then run the accessibility-tree check from this lesson against your form and compare the names with your list from step 1.

Keep the form — the lab at the end of this skill turns a signup form into a two-step flow with shared validation.

07. Review prompt

Without looking back: what three jobs does a connected label do? When does a fieldset with a legend earn its place, and what exactly does a screen reader add to each option? Which attribute decides the key the server receives, and which attribute decides whether the browser can autofill the field? Why is a card number a bad fit for type="number"?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check