No Mouse — Web Fundamentals

Tab moves the focus (the mark that shows which part of the page is selected). Enter runs the selected part, and Escape closes a dialog (a box over the page)…

Mr. Harun's hands often shake, so he doesn't use a mouse. Many other people use only a keyboard too: screen reader users, people with an injured hand, and people who are simply faster with a keyboard. A good page can be used from start to finish without a mouse.

Three keys

A keyboard user has no mouse pointer. What they have is the focus: the mark that shows which part of the page is selected.

The browser marks the focus with an outline around the selected part. Without that outline, Mr. Harun doesn't know which part he is on.

What gets Tab lost

Links (<a>), buttons (<button>) and input boxes (<input>) can take the focus automatically. A <div> made to look like a button can't: Tab skips it, and Enter doesn't run it. Use the right tag, and never remove the focus outline with the CSS rule outline: none. If the outline bothers mouse users, style it in :focus-visible, not :focus: the browser shows it when the focus comes from the keyboard, not when a button is clicked.

TL;DR: Tab moves the focus (the mark that shows which part of the page is selected). Enter runs the selected part, and Escape closes a dialog (a box over the page). Use tags that can take the focus, and keep the focus outline visible.

⚡ Three keys

Guess first: you open a Sign up dialog, a box that appears over the page, with only the keyboard. Then you change your mind. Which key closes it: Tab, Enter or Escape?

Escape. The dialog closes.

Meaning: Tab moves the focus, the mark that shows which part is selected, to the next link, button or input box. Shift+Tab goes back one. Enter runs the part that has the focus. Escape closes a box that appears over the page.

⚡ Keep the focus outline

Meaning: The browser marks the focus with an outline around the selected part. Never remove that outline with the CSS rule outline: none. Without it, keyboard users don't know which part they are on.

⚡ A div is not a button

Guess first: a <div> is made to look like a button. Can Tab reach it?

No. Tab skips it, and Enter doesn't run it.

Meaning: Links (<a>), buttons (<button>) and input boxes (<input>) can take the focus automatically. Use the right tag.

What you will learn