Is using button's onClick callback to navigate is a semantically correct?

Like in the title. Is calling
<button onClick={() => nav("/subpage")}>Btn</button>
<button onClick={() => nav("/subpage")}>Btn</button>
5 Replies
interpod
interpod16mo ago
So i always thought its not but someone just told me that I am not right. What do you think?
Rägnar O'ock
Rägnar O'ock16mo ago
if you expect the user to click something and then be redirected somewhere else, use a <a>
Kevin Powell
Kevin Powell16mo ago
That's what we have links for... Buttons are for interactions The "Simple set of rules" here puts it pretty nicely - https://a11y-101.com/design/button-vs-link
Rägnar O'ock
Rägnar O'ock16mo ago
anchor tag (<a>) do more than just change the url on click. you can right click them to copy the link, middle click to open in a new tab, press space or enter after focussing it to follow the link. Search engines use them to explore your site too. unless you want to reimplement every single one of those features... don't use buttons in place of links
interpod
interpod16mo ago
ahh thats why I hate frontend somtimes a guy who is decision making is forcing me to use button because "he says so" thanks for the help