Skip to main content

Basic keyboard shortcut support for focused links

This is one of those cases where circumstances at my job led to needing to document expected behavior in order to create “synthetic” links via JavaScript. Sometimes this sort of thing is regrettably unavoidable.

A large part of the effort was capturing all the different actions you can perform with keyboard interaction when an anchor element is focused. Turns out, there’s a lot!

I thought that sharing what I documented could be helpful to others. This is both as a resource, and also as an example of how being cavalier about non-semantic HTML can create so many problems.

Results

Update: Dave Rupert very kindly created a table-based synthesis of this work and shared it on Mastodon.

Windows

Shift + Enter

Open URL in a new window:

Function + Enter

Opens URL in current tab:

Control + Enter

Open URL in a new tab:

Option + Enter

Downloads URL:

Does nothing:

Alt + Enter

Downloads URL:

Command + Enter

Does nothing:

macOS

Note: you need to enable full keyboard access.

Shift + Enter

Open URL in a new window:

Adds URL to Reading List:

Function + Enter

Opens URL in the current tab:

Control + Enter

Opens URL in the current tab:

Does nothing:

Option + Enter

Downloads URL:

Does nothing:

Alt + Enter

Downloads URL:

Does nothing:

Command + Enter

Opens URL in a new tab:

iOS and WebKit

Note: You need to enable full keyboard access.

Shift + Enter

Open URL in a background tab.

Function + Enter

Does nothing.

Control + Enter

Does nothing.

Option + Enter

Downloads URL:

Alt + Enter

Does nothing.

Command + Enter

Opens URL in a new tab.

Shift + Enter

Open URL in a new tab.

Function + Enter

Opens URL in the current tab.

Control + Enter

Open URL in a new tab.

Option + Enter

Downloads URL.

Alt + Enter

Downloads URL.

Command + Enter

Returns to the home screen.

Testing details

Tested on Monday, August 19th, 2024 using the following hardware, operating systems and browser versions:

Other testing details

Also note that

The other thing worth stressing here is that there’s no real way to artificially recreate the context menu functionality someone would expect when right clicking/long pressing/keypressing.

An Etsy listing for a blue sweatshirt that has the word 'Bucatini' written a white collegiate font on the front. The link to the seller's shop has been right clicked and a native menu is toggled opened. The menu contains actions you can take with the link, actions that the browser can take, and actions that third party extensions can take. The menu options are open link in new tab, open link in new window, open in InPrivate window, open link in split screen window, save link as, copy link, copy link text, search link text, read aloud from here, open selection in immersive reader, translate selection to English, add to collections, add to 1Password, copy clean link location, copy link to selected text, inspect with CSS Scan, list number of characters, open in Polypane, open link in this tab, rename tab, view file in new tab, VisBug, inspect dom node, and speech options. Screenshot of the Edge browser with one tab open.
Note that these right click menu options are different for different browsers, that the native menu can exist outside the browser’s viewport, and that this sweatshirt is incredible.

This context menu includes content the operating system and browser supply, and also third party extensions and modifications someone might install and rely on. I wish we had better options for this, but I also wish browsers did a lot more to help people out.

Use appropriate, semantic HTML whenever possible, I beg you

All of the previously documented behavior needs to be built in JavaScript, since we need to go the synthetic link route. It also means that it is code we need to set aside time and resources to maintain.

That also assumes that is even possible to recreate every expected feature in JavaScript, which is not true. It also leaves out the mental gymnastics required to make a business case for prioritizing engineering efforts to re-make each feature.

Hopefully, all of this helps to communicate the value of using the proper native HTML element. You get so much extra good stuff just by virtue of using it.

Wrapping up

I don’t like writing these kinds of support tests because they’re:

My job is oftentimes the exact opposite of glamorous. In this way this post is a glimpse of some of the day-to-day realities of the work.