Mr. Tono can't see the screen. He uses a phone like yours, but his phone reads pages out loud. The program that reads them is called a screen reader. A screen reader only knows what is written in the HTML.
Name and role
For every part of a page, a screen reader says two things: its name and its role. The name comes first, then the role, which is the kind of part it is. "Send, button." "Email, edit text." "Clinic logo, image." Without the name or without the role, Mr. Tono has to guess.
<img alt="Clinic logo">gives an image a name. Withoutalt, all he hears is "image", or the file's name. A decoration image that carries no information gets an emptyalt="", so the screen reader skips it.<label for="email">Email</label>gives a name to the input box thatforpoints to. Without a label, all he hears is "edit text", which is what a screen reader calls an input box. Mr. Tono can't tell what the box is for.- A button that holds only an icon has no words that say what it does. Name it with
aria-label:<button aria-label="Close">✕</button>is read out as "Close, button". <button>gives the role of a button. A<div>with anonclick(so that it can be clicked) looks like a button, but it is read out as plain text.
The right tag already carries its own role, so you don't have to add a role yourself.
TL;DR: A screen reader (a program that reads pages out loud) says the name and the role of every part of a page. alt gives an image its name, <label> gives an input box its name, and <button> gives the role of a button.
⚡ Name and role
Meaning: A screen reader is a program that reads pages out loud. For every part of a page it says two things, its name and its role, such as "Send, button". A screen reader only knows what is written in the HTML.
⚡ An image needs a name
Write:
<img alt="Clinic logo">
Guess first: without alt, what do you hear when the screen reader reaches that image?
Only "image", or the file's name. You have to guess what the image shows.
Meaning: alt gives an image a name, here Clinic logo.
⚡ Input boxes and buttons
Write:
<label for="email">Email</label>
Meaning: A <label> gives a name to the input box that for points to, here Email. Without a label, all you hear is its role, "edit text", with no name. <button> gives the role of a button, while a <div> with an onclick (so that it can be clicked) is still read out as plain text.