Lesson 7 of 23

In progress

Course progress

HTML and CSS

Inputs, labels and helpful errors

Pick the right input type, label every field, group choices, and write error messages people can actually act on.

The input type is not a detail. It decides which keyboard appears on a phone, whether the browser offers autofill, and whether a value is checked before it reaches your server.

What you will learn

  • Match input types to the answer you need.
  • Label and group fields, including radio buttons and selects.
  • Connect error messages to the field they describe.

Types that do real work

HTML
Editable. Runs in your browser.





Press Run to see the output.

type="email" gives a phone an email keyboard and rejects values without an @. type="number" shows a numeric keypad and enforces min, max and step. type="date" opens a date picker and submits an ISO date. type="password" masks the value, though it does not make the connection secure; HTTPS does that.

autocomplete is worth setting deliberately. email, name, tel, current-password and new-password let browsers and password managers fill the right field. Getting it wrong causes autofill to put a phone number in the email box. Correct autocomplete values also cut the typing a phone user has to do, which is a usability win rather than a convenience.

Search fields use type="search", telephone numbers use type="tel" (no validation, because formats vary), and URLs use type="url".

Choices: radio, checkbox, select

Checkboxes allow zero or more selections. Radio buttons allow exactly one from a group, and the grouping comes from sharing the same name.

HTML
Editable. Runs in your browser.





Press Run to see the output.

The fieldset and legend turn three separate radios into one question. Without them, a screen reader user hears "Search, radio button" with no idea what is being asked. The value is what the server receives; the visible text is what the person reads, and they can differ.

A select is compact for long lists. For fewer than about five options, radios are faster to scan and require one click instead of two.

Text areas and hints

textarea is for multi-line answers. Its size is set with rows and cols, though CSS usually takes over.

HTML
Editable. Runs in your browser.





Press Run to see the output.

Hints belong in a paragraph tied to the field with aria-describedby, not in the placeholder. Placeholders vanish on input, and low-contrast placeholder text is a known accessibility problem.

Errors people can act on

When validation fails, say what is wrong and how to fix it, next to the field. "Invalid input" is not an error message; "Enter an email address, like name@example.com" is.

HTML
Editable. Runs in your browser.





Press Run to see the output.

aria-invalid="true" marks the field as failed, and aria-describedby makes the message part of the field’s announcement. role="alert" announces the message when it appears. Do not rely on a red border alone; colour is not a message.

Mark required fields in the label text as well as with required. An asterisk with no explanation is a puzzle; "Email (required)" is not.

Using a placeholder as the only label is the most common form accessibility failure. The hint disappears as soon as typing starts, so a person who looks away loses the question, and autofill has nothing to announce. Use a real label and keep the placeholder for an example value, if you use one at all.

Build a sign-up form with a name, an email, a password and a plan choice between Free and Pro. Label everything, group the plan with a fieldset, and add a hint under the password explaining the minimum length.

Show solution
HTML
Editable. Runs in your browser.





Press Run to see the output.

Each field has a visible label, the password has a persistent hint, and the radios share a name inside a labelled group. The minimum length is enforced by the browser and should also be checked on the server.

Recap

  • Choose the input type that matches the answer; it improves keyboards, autofill and validation.
  • Group radios with fieldset and legend, and give every control a name.
  • Tie hints and errors to fields with aria-describedby, and never use a placeholder as a label.

Next, you will structure whole pages with landmarks, so assistive technology can jump between regions.

Can I style native inputs?
Yes, though some parts, such as the date picker popup, are browser-controlled. Styling the wrapper and the visible states is usually enough; replacing inputs with divs to get a look is an accessibility risk.
What does autocomplete='off' actually do?
Browsers increasingly ignore it, especially for passwords, because autofill helps users. Prefer specific autocomplete values over turning it off.

Full syllabus

Progress is saved in this browser only. No account, no email.

Admin

About the author

Admin

Instructor and technical writer at tutorials.in

Writes beginner lessons for tutorials.in. Each lesson is checked against the language or tool documentation, and examples are run before publishing.

Reviewed by the editorial team before publishing. Last updated November 16, 2026.