---
title: "Should I use a button or a link?"
description: "Buttons do things and links go places. Learn how to choose between them so keyboard, screen reader and browser features all work as users expect."
url: https://www.danny.engineering/answer/html/should-i-use-a-button-or-a-link
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["HTML"]
---

# Should I use a button or a link?

## The short answer


Use a link (`<a href>`) when the user goes somewhere: another page, another site, a section of the current page or a file. Use a button (`<button>`) when the user does something on the current page: submits a form, opens a dialog, toggles a menu, saves or deletes. How it looks is a styling choice and should not decide which element you use.


```html
<!-- Goes somewhere: a link -->
<a href="/pricing">See pricing</a>

<!-- Does something: a button -->
<button type="button" id="open-menu">Menu</button>
```


## Why it happens


The question comes up because both elements look clickable and both can run JavaScript, so it is tempting to pick whichever is easier to style. But the browser, assistive technology and the user all treat them differently.


A link has a URL. Because of that, people can open it in a new tab, copy its address, bookmark it, see the destination in the status bar and use the back button afterwards. Screen readers announce it as a link and list it in their links menu. It is activated with the Enter key.


A button has no URL. Screen readers announce it as a button, which tells the user that pressing it will change something here. It is activated with both Enter and Space. Inside a form it submits by default, and it can be disabled with the `disabled` attribute.


When the element does not match the behaviour, those expectations break. A link that opens a modal leaves a useless entry in the history and does nothing when opened in a new tab. A button that navigates cannot be opened in a new tab or copied.


## How to fix it


### Pick the element from the behaviour


Ask one question: does this change the URL? If yes, use a link with a real `href`. If no, use a button. A few common cases:

- Navigation menus, breadcrumbs, pagination and "read more": links.
- "Skip to content" that jumps to an id on the page: a link with `href="#main"`.
- Download a file: a link, optionally with the `download` attribute.
- Open or close a dialog, accordion or dropdown: a button.
- Like, save, delete, add to basket, copy to clipboard: a button.
- Submit a search form: a submit button, even though the result is a new page, because the form does the navigating.

### Style the element, do not swap it


If the design calls for a link that looks like a button, or a button that looks like a link, keep the right element and change the CSS.


```css
.button-like {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  background: #1d4ed8;
  color: #fff;
  text-decoration: none;
}

.link-like {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}
```


### In frameworks, use the router's link for navigation


For client-side routing, use the framework's link component (such as `Link` in Next.js) rather than a button with a click handler that calls `router.push`. The link component renders a real `<a href>`, so new-tab and copy-link still work, and the framework can prefetch the route.


```typescript
import Link from "next/link";

export function Nav() {
  return <Link href="/articles">Articles</Link>;
}
```


Keep `router.push` for navigation that happens as a result of an action, such as redirecting after a form is saved.


### Replace clickable divs


A `<div>` or `<span>` with a click handler is neither. It is not focusable with the Tab key, does not respond to Enter or Space and is announced as plain text. You can patch it with `role`, `tabindex` and key handlers, but a real `<button>` gives you all of that for free.


```html
<!-- Avoid -->
<div class="close" onclick="closePanel()">Close</div>

<!-- Prefer -->
<button type="button" class="close" onclick="closePanel()">Close</button>
```


## Common pitfalls

- Using `href="#"` or `href="javascript:void(0)"` on a link that runs an action. It is a button pretending to be a link; use a button.
- Leaving out `href` on an `<a>`. Without it the element is not focusable and is not exposed as a link.
- Forgetting `type="button"` on buttons inside forms, so they submit the form by accident.
- Putting a button inside a link, or a link inside a button. Interactive elements must not be nested, and the result is unpredictable for keyboard and screen reader users.
- Icon-only buttons and links with no accessible name. Add visible text, or an `aria-label` if the design truly has no text.

## Related reading

- [MDN: The anchor element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a)
- [MDN: The button element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button)
