A significant number of people navigate the web without a mouse, including keyboard users, people using switch devices, and anyone whose pointing device has failed. Keyboard support is not an exotic requirement, and most of it comes free with correct markup.
What is focusable by default
Links with an href, buttons, form controls, elements with the contenteditable attribute, and a few others are focusable without any work. They appear in the tab order automatically and respond to the expected keys.
Everything else is not focusable, which is correct: a paragraph is not something anyone needs to tab to. The problem arises when an element that should be interactive is not one of the focusable ones, which is what happens every time a div is given a click handler.
Focus order follows the source
The tab order is the order elements appear in the document, not the order they appear on screen. Usually those match. With CSS layout they can diverge dramatically.
Flexbox and Grid can reorder items visually with a single property, and Grid can place an element anywhere regardless of its position in the markup. When that happens, a keyboard user tabs in an order that has no relationship to what they can see, which is disorienting even for someone who can see the page and worse for someone using magnification.
The rule is to keep the source order matching the logical reading order, and use layout to arrange rather than to reorder. Where a visual order genuinely differs, that is usually a sign the markup should be restructured instead.
The tabindex attribute
Three cases, and only two of them are safe.
A value of zero makes an element focusable in its natural document position. This is the correct way to add a custom control to the tab order, though a real button is almost always better.
A value of minus one makes an element focusable by script but not by tabbing. This is right for something you need to move focus to programmatically, such as a heading after a page section changes, or an error summary after a failed form submission.
A positive value places an element before everything with a value of zero, in numerical order. This is almost always a mistake. It creates a tab order detached from the document, it applies across the entire page, and it becomes unmaintainable the moment anyone adds another element. Nothing that a positive tabindex achieves cannot be achieved better by reordering the markup.
Never remove the focus outline
The outline on a focused element is how a keyboard user knows where they are. Removing it without providing a replacement makes a site effectively unusable without a mouse, and it is done routinely because designers dislike how it looks.
:focus-visible { outline: 3px solid #1a73e8; outline-offset: 2px; } The focus-visible pseudo-class is the modern answer to the underlying complaint. It applies only when the browser judges that a focus indicator should be shown, which means keyboard users see it and mouse users clicking a button do not. That removes the reason people were suppressing it in the first place.
Whatever indicator you use, ensure it has adequate contrast against the background and is not clipped by an overflow rule on a parent, which is a common way for a perfectly good outline to become invisible.
Focus must not get lost
When content changes without a page load, focus can end up on an element that no longer exists, at which point it reverts to the top of the document and the user has to start again.
Move focus deliberately whenever the context changes. Opening a dialog moves focus into it and closing it returns focus to the trigger. Deleting an item moves focus to a sensible neighbour. Loading new content into a region moves focus to its heading, which usually needs a tabindex of minus one to be focusable.
Keyboard traps
A keyboard trap is any point where focus enters something and cannot leave. Embedded content and custom widgets are the usual culprits, and a modal is a deliberate trap that must release focus on close.
Testing for this is simple: tab through the entire page from the address bar and confirm you can reach the end and come back. Anywhere you get stuck is a defect.
Test by putting the mouse away
The most effective check available is to unplug the mouse and use the site. Tab through a form, open the menu, complete a purchase. Problems that are invisible in code review become obvious within a minute, and most of them are quick to fix once found.