Forms are HTML-first: labels tied to inputs, correct type attributes, and clear errors. CSS improves clarity but cannot replace associations.
Non-negotiable HTML
<label for="id">matchingidon the control.type="email",required,autocompletewhere appropriate.- Submit with
<button type="submit">inside<form>.
CSS techniques
- Stack fields with
display: grid; gap: 1rem;. - Full-width inputs:
width: 100%inside a bounded form. :focus-visiblerings on inputs for keyboard users.
Practice
- Click the label text—focus should jump to the input.
- Remove
for/idpairing and notice the UX regression.
Deep dive: HTML forms lesson.
Important interview questions and answers
- Q: Why associate labels with inputs?
A: Larger click targets, screen reader names, and correct focus behavior. - Q: `button` vs `input type="submit"`?
A: Both submit; ` - Q: Can CSS alone make a form accessible?
A: No—semantics and labeling come from HTML; CSS only helps visibility.