Accessibility・Interaction and input

Always give a form a label

A label reliably tells you "what goes in" an input field. It doesn't just help screen readers — it also widens the area you can tap. One tag everyone gains from.

An input field sitting there all alone, with no clue what to put in it — a lot of the trouble people have with forms comes from a missing label. <label> tells screen reader software “what this field is,” and on top of that it widens the clickable area — a tag everyone gains from.

HTMLBundle your inputs with a formHow to build the form itself (the HTML side) is in this lesson

Let’s try it out: a label widens the tap area

You can feel the effect best with a checkbox. Try clicking the text.

On the top one, pressing anywhere on the text checks the box. On a phone’s small screen, this difference directly affects how easy it is to use.

There are two ways to write it

Wrapping is the easiest.

<label>Name
  <input type="text" name="name" />
</label>

When your design needs them placed apart, link them with for and id.

<label for="name">Name</label>
<input type="text" id="name" name="name" />

The key is to match the for value and the id value. Both ways have the same effect.

Give each group of questions a “name plate” too

For radio buttons and checkboxes, even if you put a <label> on each option, sometimes “which question these options belong to” doesn’t come across. Wrap the group of related questions in <fieldset>, and write the question text in <legend>.

<fieldset>
  <legend>What's your favorite snack?</legend>
  <label><input type="radio" name="snack" />Sunflower seeds</label>
  <label><input type="radio" name="snack" />Pinecone</label>
</fieldset>

Screen reader software reads the question and options as a set, like “What’s your favorite snack? Sunflower seeds, radio button.” It prevents the confusion of hearing only the options without knowing the question.

fieldset draws the frame and legend draws its heading automatically. The question and options look like one set, so it’s easier to understand by eye too.
HTMLChoosing inputs (checkboxes, radio buttons, select)The basics of radio buttons and checkboxes are in this lesson

A placeholder can’t replace a label

You often see forms that get by with just a faint hint (placeholder).

<input type="text" placeholder="Name" />  <!-- ❌ can't replace a label -->

There are three reasons this is bad.

  • It disappears once you start typing — “wait, what was this field for again?” happens
  • The color is faint — to begin with, it doesn’t even meet the contrast passing line from two lessons back
  • Depending on the screen reader, it may not be read out

Keep the placeholder to an input example like “e.g. Shima,” and always put the name plate in a <label>.

<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="e.g. Shima" />  <!-- ○ divide the roles -->

The name plate stays visible in the <label> at all times, and the input example goes in the placeholder — with this division of roles, you’re fine even when the hint disappears as you start typing.

Try typing in both fields. On the top one you forget “what was this field for,” but on the bottom the label stays as it is, so you never get lost.

Show “required” with words

“I made the required fields red, so people will know, right?” — this violates the don’t rely on color alone rule from the contrast lesson. Write that a field is required in words.

<label for="email">Email address (required)</label>
<input type="email" id="email" name="email" required />

Writing “(required)” in the label gets the same information to people who see it and people who hear it read aloud. Adding the required attribute makes the browser prompt them automatically if they try to submit while it’s empty, so add it as well.

Press “Send” while it’s empty, and the browser automatically tells you “Please fill out this field.” Just adding required gives you this check.

Summary of this lesson

  1. A <label> on every input field — it reaches screen readers, and widens the pressable area
  2. There are two ways to write it: “wrap it” or “connect it with for and id”
  3. A placeholder is an input example. Don’t use it as a label

FAQ

Can I write both a label and a placeholder?
Yes, using both is recommended. Keep the name plate always visible with the label, and put an input example like 'e.g. Shima' in the placeholder. Getting by with a placeholder alone is the thing to avoid.
Should the label go above or to the left of the input field?
For text input fields, place it above or to the left (above is the readable standard on phones). Only for checkboxes and radio buttons, by convention, put the text on the right side.
Can the for and id attribute values be anything?
They can be anything, as long as the for and id values match exactly and you don't reuse the same id within the page. If even one character differs, they won't link.