Sub topic 3
Where to put the label
This chapter assumes you can write basic HTML forms and CSS layouts, and that you know a label must be tied to its input with matching for and id values. Here you will choose where the label goes relative to the field.
The three common placements
A label's position changes how fast people scan the form and how well it adapts to small screens. The three common options are:
- Top-aligned: the label sits above the field.
- Left-aligned: the label sits to the left of the field, on the same line.
- Floating: the label starts inside the field like a placeholder, then shrinks and moves above the field when the user focuses it or types.
Top-aligned labels are the default
Top-aligned labels work in most cases. The eye moves down in one straight line, so people complete the form quickly. The label and field share the full width of the container, so long labels and translated text have room to grow. The layout also needs no change on narrow screens, which makes it the safest choice for mobile.
The cost is height. The form takes more vertical space than a left-aligned one.
<style>
.field label { display: block; margin-bottom: 0.25rem; }
.field input { width: 100%; max-width: 24rem; }
</style>
<div class="field">
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required>
</div>Left-aligned labels
Left-aligned labels save vertical space and suit long, dense forms where people already know the fields, such as an admin screen. They have two weaknesses. The eye must zigzag between label and field, which slows scanning. Labels also need a fixed column width, and that width breaks when a label is long or translated. Below a certain screen width, you must switch to top-aligned anyway.
If you use them, put a media query in place:
.field { display: grid; grid-template-columns: 12rem 1fr; gap: 0.5rem 1rem; align-items: center; }
@media (max-width: 40rem) {
.field { grid-template-columns: 1fr; }
}Right-aligning the label text in its column puts it closer to the field, but it leaves a ragged left edge that is harder to read. Left-aligned text in the column is usually easier to read.
Floating labels
A floating label saves space and looks tidy. It also causes several problems:
- The label text is small once it floats, often below a comfortable reading size.
- Before the user types, the label looks like a placeholder, so people may think the field is already filled in.
- Long labels get truncated inside the field.
- The animation depends on JavaScript or fragile CSS, and it can fail with browser autofill.
Floating labels are not forbidden, but they need careful testing. If you cannot justify one for a specific reason, use a top-aligned label.
Choosing a placement
| Situation | Placement |
|---|---|
| Most forms, especially on mobile | Top-aligned |
| Dense, repeated forms for expert users on wide screens | Left-aligned, with a top-aligned fallback |
| Space is extremely tight and you can test the result | Floating, with caution |
Whatever you choose
Keep these rules for every placement:
- The label stays visible. Never remove it once the user starts typing.
- The label is a real
<label>element associated with its input. - Use one placement across the whole form. Mixing them forces people to relearn the layout.
- Keep the label close to its field and farther from the neighbouring field, so the pairing is clear.
Exercise
A team wants a long signup form to be left-aligned so it fits on one screen. Name two problems with this choice, and one fix.
Show answer
Possible problems: the eye must zigzag between label and field, which slows scanning, and the fixed label column breaks with long or translated labels. On narrow screens it also does not fit. A fix is to use top-aligned labels by default, or to keep left-aligned labels only on wide screens and switch to top-aligned labels with a media query on small screens.