Buttons vs Links: Choosing Correctly
You'll learn: When to use a <button> versus an <a> tag based on what action the user is performing.
The Core Difference
Though buttons and links can be styled to look identical, they serve fundamentally different purposes:
- Links (
<a>) navigate the user somewhere — to another page, a different section, or a downloadable file. They change the user's location. - Buttons (
<button>) perform actions — submit forms, open modals, toggle visibility, or trigger JavaScript functions. They change the page's state or behavior.
Think of it like a car: a link is like the steering wheel (it takes you places), while a button is like the horn or windshield wipers (it does something right where you are).
Why It Matters for Accessibility
Assistive technologies like screen readers announce these elements differently:
- A link is announced as "link" and users expect pressing Enter to navigate
- A button is announced as "button" and users expect pressing Space or Enter to activate it
When you use the wrong element, you create confusion and break expectations. A link styled as a button that doesn't navigate anywhere frustrates users relying on assistive technology.
The Simple Rule
Ask yourself: "Does this take the user somewhere, or does it do something?"
- Takes somewhere → use
<a href="..."> - Does something → use
<button>
Don't use <a href="#"> or <a href="javascript:void(0)"> with click handlers when you mean button. Just use an actual <button>.
Key Takeaway: Use <a> tags for navigation between locations and <button> tags for actions that affect the current page — choosing correctly ensures assistive technologies convey the right purpose to all users.