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
interpodOP2y 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'ock2y ago
if you expect the user to click something and then be redirected somewhere else, use a <a>
Kevin Powell
Kevin Powell2y 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'ock2y 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
interpodOP2y 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
Want results from more Discord servers?
Add your server