How do you decide which HTML element to use for an interactive control, and why does that choice matter beyond styling?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Probes whether the candidate reasons about native element semantics, accessibility, and behavior contracts when choosing markup, instead of treating all elements as interchangeable styled boxes.

What to say

What to avoid

Example answers

Strong: I pick the element by the behavior I need, not the look. If it navigates I use an <a href> so middle-click and right-click 'open in new tab' work; if it triggers an action I use a <button> so I get focus, Enter and Space activation, and a button role for free. I only reach for tabindex and ARIA roles when no native element fits, because reimplementing native behavior on a <div> is where keyboard bugs creep in.

Weak: Honestly I just use divs and spans and add onClick, then style them however the design needs. If accessibility comes up later I'll throw a role='button' on it. The semantic tags are mostly for SEO.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.