Should I use HTML buttons or anchor tags for triggering JavaScript actions?
I’m confused about the best practice for clickable elements. I see some developers using a href="#" for things that trigger a JS function, while others use the button tag. Which one is better for SEO and accessibility? Does it matter if I style them both to look like buttons anyway, or is there a fundamental structural difference I should be aware of?
2025-09-05 in Software Development by Karen Taylor
| 13766 Views
All answers to this question.
This is a classic debate, but the rule of thumb is simple: if it changes the URL or takes the user to a new location, use an a (anchor) tag. If it performs an action on the current page, like opening a modal, submitting a form, or toggling a menu, use a button tag. Using an anchor tag with href="#" is considered bad practice because it can confuse screen readers and search engines. Buttons are accessible by default via the spacebar and enter key, whereas anchors only respond to the enter key unless you add extra JavaScript. Stick to the intended purpose of the element.
Answered 2025-09-07 by Sandra Lewis
Do you ever find that using a button tag causes issues with your CSS resets, or do you find it easier to style than an anchor tag with a class?
Answered 2025-09-10 by James Walker
-
James, I find that a quick border: none; background: none; reset on buttons makes them just as easy to style as links. My main concern was actually the "open in new tab" behavior. Users expect a link to be able to open in a new tab, but you can't really do that with a button triggering a JS function. This reinforces Sandra's point that the functionality should dictate the tag choice to avoid frustrating the user
Commented 2025-09-13 by Richard Harris
From an SEO perspective, Google might try to crawl those # links, which is a waste of your crawl budget. Using a button prevents this entirely.
Answered 2025-09-16 by Barbara Hall
-
Exactly, Barbara. Keeping the crawl budget focused on actual content pages rather than interface triggers is a subtle but effective SEO strategy.
Commented 2025-09-18 by Karen Taylor
Write a Comment
Your email address will not be published. Required fields are marked (*)

