Sub topic 3
Where to put the label
This chapter assumes you can write basic HTML forms and CSS layouts, and that you know why every control needs an associated <label> (covered in the previous chapter). Here the question is where the visible label sits relative to its field, and what that choice does to scanning speed, small screens, translation, and accessibility.
Why placement matters
The label's position changes how quickly people read a form and how often they make mistakes. It also affects how the form behaves when the viewport is narrow, when text is zoomed, or when a translation makes the label twice as long.
There are three common placements:
- Top-aligned: the label sits above the field.
- Left-aligned: the label sits beside the field, to its left, in a column of its own.
- Floating: the label starts inside the field like a placeholder, then shrinks and moves above the field when the user focuses it or types.
Eye-tracking studies, including a widely cited 2006 study by Matteo Penzo for UX Matters, found that top-aligned labels need the fewest eye movements. The user reads the label and the field in one downward motion. These findings are a good default, but they come from specific forms and users. Treat them as a starting point and test your own form.
Top-aligned labels
Top-aligned labels are the best default for most forms.
Strengths:
- One fixation path. The label and field are in the same vertical line, so the eye does not travel sideways.
- Room for long labels. The label can take the full width of the form, so long or translated text does not break the layout.
- Responsive by default. The same layout works on a phone and on a desktop. You do not need a breakpoint to switch layouts.
- Zoom friendly. At 400% zoom, a single column reflows without horizontal scrolling, which WCAG 2.2 success criterion 1.4.10 (Reflow) requires.
Weaknesses:
- The form is taller, so it needs more scrolling.
- A long form of short fields, such as a list of settings, can feel sparse.
<style>
.field { display: flex; flex-direction: column; gap: 0.25rem; margin-block-end: 1rem; max-width: 24rem; }
.field label { font-weight: 600; }
.field input { padding: 0.5rem; font: inherit; }
</style>
<form>
<div class="field">
<label for="full-name">Full name</label>
<input id="full-name" name="name" type="text" autocomplete="name">
</div>
<div class="field">
<label for="work-email">Work email address</label>
<input id="work-email" name="email" type="email" autocomplete="email">
</div>
<button type="submit">Create account</button>
</form>Note that the order in the HTML source is label, then input. That order matters for screen readers and for keyboard users, and CSS changes should not reverse it.
Left-aligned labels
In a left-aligned layout, labels form a column on the left and fields form a column on the right. Within the label column, text is aligned either left or right.
- Right-aligned label text sits close to its field, so the label and field are easy to pair. The left edge of the labels is ragged, which makes the labels harder to scan as a list.
- Left-aligned label text gives a clean left edge for scanning labels. Short labels leave a large gap before their fields, and the pairing gets weaker.
Strengths:
- The form is compact vertically.
- Users who only need to scan the labels, for example to find one field in a long settings page, can read the label column on its own.
- Users who revisit and edit data may find it easier to compare values in a table-like layout.
Weaknesses:
- Users need two eye movements per field (label, then across to the field).
- Long labels wrap into several lines or force the label column to be wide, which squeezes the field.
- Translated labels, for example German, often overflow a column sized for English.
- On narrow screens the layout must collapse to top-aligned, so you maintain two layouts.
A common approach is to use a left-aligned layout only when the viewport is wide, and fall back to top-aligned otherwise.
.field { display: flex; flex-direction: column; gap: 0.25rem; margin-block-end: 1rem; }
@media (min-width: 40rem) {
.field {
display: grid;
grid-template-columns: 12rem minmax(0, 24rem);
align-items: baseline;
column-gap: 1rem;
}
.field label { text-align: right; }
}Using align-items: baseline keeps the label text on the same line as the text inside the field. If you use center instead, a field with a hint or error beneath it will misalign.
Floating labels
A floating label is placed inside the field. When the field receives focus or contains a value, the label moves up and shrinks. Material Design popularized the pattern.
The appeal is a compact form, since label and field share one box. The costs are well documented:
- Small text. The label shrinks after the user starts typing, often to 12px or less, which can fail contrast and legibility needs.
- Truncation. The label has to fit inside the field at rest. Long labels get cut off, so you end up shortening the wording.
- Confusion with filled-in values. A pre-filled field, such as one filled by autofill, can look like it has no label, or the label can overlap the value if the script does not detect the autofill.
- Hint text has no home. There is little room for persistent hints.
- Fragile implementation. Many floating-label implementations rely on
:placeholder-shownand a placeholder of a single space, which is a hack that breaks easily. - Zoom and text spacing. Larger text sizes can cause the animated label to collide with the input text.
If you must use one, keep the real <label> element, associated with for and id, and make sure the label remains visible and legible in its small state.
<style>
.float { position: relative; max-width: 24rem; margin-block-start: 1rem; }
.float input {
width: 100%; box-sizing: border-box;
padding: 1.4rem 0.75rem 0.4rem; font: inherit;
}
.float label {
position: absolute; inset-inline-start: 0.75rem; inset-block-start: 0.9rem;
transition: transform 0.15s, font-size 0.15s;
transform-origin: left top; pointer-events: none;
}
.float input:focus + label,
.float input:not(:placeholder-shown) + label {
transform: translateY(-0.6rem) scale(0.85);
}
@media (prefers-reduced-motion: reduce) {
.float label { transition: none; }
}
</style>
<div class="float">
<input id="city" name="city" type="text" placeholder=" " autocomplete="address-level2">
<label for="city">Town or city</label>
</div>In this example the input comes before the label in the source, so the sibling selector input + label can work. That is the opposite of the earlier examples, and it is one of the reasons floating labels are awkward. Screen readers handle it correctly because for and id define the association, but the reading order in the markup is reversed.
Comparing the three
| Placement | Scanning speed | Vertical space | Narrow screens | Long or translated labels | Risk |
|---|---|---|---|---|---|
| Top-aligned | Fast | More | Works without changes | Handles well | Low |
| Left-aligned | Slower, two eye movements | Less | Needs a fallback layout | Overflows easily | Medium |
| Floating | Varies | Least | Works | Truncates | Highest |
Choosing a placement
Use these criteria in order:
- Default to top-aligned. It has the fewest failure modes.
- Move to left-aligned only for a reason. Good reasons are dense forms that users scan or edit repeatedly, and wide layouts with short labels in one language.
- Use floating labels only when a design system forces them. If you do, treat the checks below as requirements.
Rules that apply to every placement
- Keep the label visible. Never remove the label when the user focuses or types. A label that vanishes forces users to remember the question.
- Keep the label close to its field. The space between a label and its own field must be clearly smaller than the space between that field and the next label. This is the Gestalt principle of proximity. If the gaps are equal, users cannot tell which label belongs to which field.
- Use the
<label>element in every case. Positioning is a CSS decision. The programmatic association is separate and must stay in place. - Make the label clickable. A
forandidpair gives users a larger click target, which helps people with motor impairments and anyone on a touch screen. - Keep the same placement across the whole form. Mixing placements makes users relearn the layout at each field.
- Check contrast. Label text needs at least 4.5:1 contrast against its background for normal-size text (WCAG 1.4.3).
- Check translated text. Test with a long language, or pad English strings by 30–40%, to see whether the layout holds.
Testing your placement choice
Run these checks before settling on a layout:
- Zoom the page to 200% and then 400%. Confirm that labels do not overlap fields and that nothing needs horizontal scrolling.
- Increase text spacing (line height 1.5, letter spacing 0.12em) and confirm that nothing is clipped, as WCAG 1.4.12 requires.
- Replace labels with a longer translation and check wrapping.
- Trigger browser autofill and confirm that labels and values do not overlap.
- Tab through the form and confirm that the visible focus indicator is easy to match with its label.
- Click each label and confirm that the correct field receives focus.
Exercise
A product team wants a compact sign-up form for a mobile-first app that will ship in English, German, and Finnish. A designer proposes left-aligned labels in a 10rem column to save vertical space. Explain whether you would accept the proposal, and name the layout and CSS rule you would use instead.
Show answer
Reject it as the default. Left-aligned labels in a fixed 10rem column will overflow or wrap badly with long German and Finnish labels, and a 10rem column leaves too little room for the field on a phone. Use top-aligned labels, with a flex column per field, so each label can use the full form width and the layout reflows at any zoom level. If space on wide screens matters, add a media query such as @media (min-width: 40rem) that switches to a grid with a label column, and keep top-aligned as the narrow-screen layout.
Exercise
A floating-label field shows its label at the small size above the input, but when Chrome autofills the field the label stays inside the input and overlaps the autofilled text. Which two things could you change so the label state does not depend only on JavaScript detecting focus or input events?
Show answer
First, drive the label state from CSS instead of script: keep a placeholder of a single space and use the :placeholder-shown selector (and :autofill where supported) so the label moves up whenever the field is not empty, including autofilled values. Second, if that is not reliable enough, switch to a top-aligned label, which has no state to get wrong. Either way, keep the real <label for> element in the markup.