Software Development Community Question

Should I use HTML buttons or anchor tags for triggering JavaScript actions?

Posted on 2025-09-05 • In Software Development • By Karen Taylor

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?

3 Answers 13,793 Views

All answers to this question 3 Answers

Sandra Lewis Answered on 2025-09-07
Answered

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.

James Walker Answered on 2025-09-10
Answered

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?

Richard Harris Commented on 2025-09-13
Commented

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

Barbara Hall Answered on 2025-09-16
Answered

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.

Karen Taylor Commented on 2025-09-18
Commented

Exactly, Barbara. Keeping the crawl budget focused on actual content pages rather than interface triggers is a subtle but effective SEO strategy.

Write a Comment

Your email address will not be published. Required fields are marked (*)

Join the LearnersEra Community

Ask questions, share knowledge and learn from professionals across technology, project management and certification topics.

Change Country and Nearest City

Select your country and nearest city to see courses available in your region.