HTML · The document layer
When should you use a button instead of a link?
Short answer
Use a button for an action on the current page and a link for navigation to another URL. Buttons respond to Enter and Space and are announced as buttons; links respond to Enter and are announced as links.
The choice is about behaviour, not appearance. A button performs an action such as opening a dialog or submitting a form. A link navigates to a URL that the user could open in a new tab or copy.
<button type="button" onclick="openFilters()">Open filters</button>
<a href="/products?sort=new">New arrivals</a>Why this matters
- A button activates with both Enter and Space; a link activates with Enter
- A link supports open in new tab, copy link address and browser history
- A button has a button role; faking it with a div loses keyboard and screen reader support
- Inside a form, a button defaults to submit, so set type=button when it is not submitting
- Visually styling a link like a button does not change its semantics
A common mistake is an anchor with href=# used as a JavaScript action. It jumps to the top, appears in the tab order as a link and misleads assistive technology. Use a button and style it however you like.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is wrong with `a href=#` as a click action?
- 2How does keyboard activation differ between buttons and links?
- 3What is the default button type inside a form?
- 4Can a link be styled to look like a button?
Say it in the interview
I use a button when the control performs an action on the current page, and a link when it navigates to a URL. Buttons respond to Enter and Space and are announced as buttons, while links respond to Enter and support open in new tab and copy link. Using a clickable div or an anchor with href=# loses those behaviours and confuses assistive technology.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live HTML mock interview and get scored feedback on depth, clarity and confidence.