When to use a button and a link
For most document type websites the question between links and buttons doesn't really exist. But in application type websites, it's often that developers don't pick the right one or that designers make links look like buttons.
So to make it clear:
- An
<a>
is for a page change or a new tab. When changing page, a screen reader user will be automatically moved to the top of the page and will start reading it from there. - A
<button>
is for activating something like a modal or a form. Once pressed, even if things change in the page, it doesn't move a screen reader user somewhere else and it doesn't vocalize anything.
This difference of behavior is super important, especially in single page JavaScript web applications where urls are changed dynamically, but no page change is triggered in the browser! When such a thing happens, the developer has to manually move the focus of the screen reader user to the next point of interest inside the app and vocalize what happened and where the user is.
To do this, the developer has to use the .focus()
function in JavaScript. I'm not 100% sure about how to vocalize the page change so I'm not gonna give any advice on this. If you know good practices please contact me so I can update this part.
One last thing: I don't care about your reasons, don't replace a <button>
by a <div>
.
Next: The mess of strong b em and i
Generated: November 12th, 2021