Choosing keyboard shortcuts for websites

Keyboard shortcuts give users fast methods to interact with an application. Native apps like Microsoft Word have shortcuts for nearly every editor command. This lets the user focus on authoring text rather than shifting their focus to navigating an involved File menu.

If the web is the application platform of the future, websites should also offer keyboard shortcuts for efficiency. However, you can’t pick just any shortcuts.

For example, a few weeks ago a bug was reported in ProseMirror, an in-browser text editor. Normally when a Mac user is editing text, pressing Option+Right moves the cursor right by one word. Pressing this shortcut in ProseMirror was not doing this, because Option+Right was internally bound to custom, two-step shortcuts. For example, pressing Option+Right then * in ProseMirror would wrap the text selection in a bullet list. Oh crap!

This bug has been fixed 🎉 but gives you a feel for the rocky terrain of keyboard shortcuts on the web.

Use familiar shortcuts

Google, Twitter and Facebook provide some common shortcuts. It’s likely your users will try these shortcuts on your site too.

If your website is a list of items (like emails in GMail or tweets in Twitter), pressing Up and Down arrow may navigate the user’s focus through the list. The browser default of scrolling up and down the screen is ignored, replaced by a behavior similar to the default in spirit but with more awareness of user context. The keys J and K often navigate up and down as well, which is a shortcut borrowed from the Vim text editor.

The Enter key may expand the view of a selected item (like opening an email).

The / key (forward slash) may focus the user’s text cursor in the site search (Also from Vim). Update: Eevee told me the / key opens Find in Page in Firefox, so keep that in mind while deciding whether to use this shortcut.

Make Shortcuts Discoverable

If your website offers keyboard shortcuts, your users will want to know what they are. Provide a link somewhere in your application to see a list of them, like under a menu. Users should not have to try key combinations to find shortcuts like a game of bobbing for apples. Shortcuts should be discoverable.

Twitter.com’s keyboard shortcut help modal

Pressing the ? key (question mark) is a common shortcut to bring up a list of available shortcuts.

Keep in mind that screen readers used by those with impaired vision override almost every single key shortcut. If a shortcut is critical to navigate your website consider placing them under modifier keys.

Using modifier keys

You may want to create multi-key shortcuts that include modifier keys (e.g. the Control, Command or Alt key).

If your website includes text input fields, you may want shortcuts on modifier key combinations so can trigger a shortcut while focused in an input field. If your website has a save command, you may want the familiar shortcut Command+S/Control+S to trigger this save command, rather than the browser default of saving the HTML of the current webpage to your computer.

A user’s operating system and web browser have built-in shortcuts which are bound to various modifier and key combinations. Here is a list of operating system and browser keyboard shortcuts. Are your OS/browser shortcuts not listed? Let me know and I’ll give you edit access.

With this list you can make informed decisions about what keyboard shortcuts to choose.

Most operating system behaviors cannot be prevented. e.g. Pressing Command+Tab on a Mac to switch between apps, and can’t be disabled.

Browsers also limit what shortcuts can be disabled. Command+1 in Mac Chrome switches the user to the first tab. This can be overridden, but not in Safari. See what shortcuts can be disabled in your browser in this demo, which tries to prevent the default behavior when any key is pressede.

Respect user intent

It is up to you to decide what shortcuts to offer users, and whether to override browser shortcuts.

Lea Verou makes an interesting case for overriding browser defaults. Her argument is that if your websites has tabs, overriding the browser shortcuts for switching between tabs is useful, and avoids hard-to-remember shortcuts like Control+Alt+1. She says,

the browser environment is merely a host, like your OS. The focus is the web app. When you’re working in a web app and you press a keyboard shortcut, chances are you’re looking to interact with that app, not with the browser Chrome.

These choices are up to you, but they are user experience questions which I don’t have answers for. Make informed decisions and consider what the user intends to do when they press a shortcut, and how your application reacts to it.

There are some shortcuts that should just work. Take the ProseMirror bug I mentioned before. When a Mac user is entering text, pressing Option+Right moves their text cursor right by one word. I’d expect this to work when I’m typing into a text field on a website, so a shortcut shouldn’t override it while I’m typing.

Expect edge-cases in international contexts

Operating systems around the world have made hard choices in the last 30 years to make the QWERTY keyboard work across different languages. This can lead to unexpected behavior, for example Polish users could not enter the Ś character into Medium’s editor, and saw their document getting saved instead. Medium fixed this bug 🎉 and if you get a bug like this, you should respect user intent too!

Now close this tab in your browser (Command+W/Control+W) and go add shortcuts to your website!

Leave a Reply

Your email address will not be published. Required fields are marked *