How To Make A Button Link In Html

5 min read

Creating a clickable button that takes users to another page is one of the most common tasks in web development, yet many beginners struggle to get it right. Learning how to make a button link in HTML is a foundational skill that combines structure, styling, and accessibility. The good news is that there are several reliable approaches, and once you understand the strengths and weaknesses of each, you will always know which one to reach for.

Understanding the Difference Between a Button and a Link

Before writing any code, it helps to clarify a distinction that trips up a lot of newcomers. In HTML, <a> and <button> are not interchangeable elements. They serve different purposes, and browsers, screen readers, and search engines treat them differently Easy to understand, harder to ignore..

  • The <a> (anchor) element is designed for navigation. It moves the user from one location to another, whether that is a different page, a section of the same page, or an external resource.
  • The <button> element is designed for actions. It submits a form, opens a modal, toggles a menu, or triggers JavaScript.

So when someone says "button link," they usually mean one of two things: a link that looks like a button, or a button that behaves like a link. Choosing correctly matters for usability, keyboard navigation, and search engine optimization Easy to understand, harder to ignore..

Method 1: Style an Anchor Tag to Look Like a Button (Recommended)

We're talking about the cleanest and most accessible approach. You keep the semantic meaning of a link while giving it the visual appearance of a button using CSS.

Sign Up Now

Then apply styling:

.btn {
  display: inline-block;
  padding: 12px 28px;
  background-color: #2563eb;
  color: #ffffff;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 600;
  transition: background-color 0.2s ease;
}

.btn:hover {
  background-color: #1d4ed8;
}

.btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

Why this method wins: the element is genuinely a link, so it supports right-click "open in new tab," middle-click, bookmarking, and copying the address. Screen readers announce it as a link, which matches user expectations. Search engines can follow the href and pass link equity Simple as that..

The display: inline-block declaration is essential because anchor tags are inline by default, and inline elements ignore vertical padding in ways that break the layout.

Method 2: Use a Button Inside a Form

If you are working inside a form and need the button to figure out to a different destination, the formaction attribute is a valid HTML5 solution Took long enough..

This is useful in multi-step forms where different submit buttons lead to different endpoints. Still, it only works within a form context, so it is not a general-purpose replacement for links.

Method 3: JavaScript with onclick

You will see this pattern everywhere, and it does work:


Or with a cleaner separation of concerns: