Blog: Expanded Universe

JavaScript: is the user on an Apple device?

Often, you should just use feature detection instead of asking this question. But if your underlying question is "does the user expect Control or Command as a modifier key?", there's currently (November 2026) no good alternative. The short answer:

const isApple = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
const isModified = (event) => isApple ? event.metaKey : event.ctrlKey;
const modifierLabel = isApple ? "⌘" : "Ctrl";

(Even then, you might just want to check either metaKey or ctrlKey, it depends. Somebody has proposed a shortcut key constant over at w3c/uievents#412, but it doesn't appear to have gained traction.)

navigator.platform seems fine to use now, but has a bit of a rocky history. MDN's browser compatibility project

Libraries using the regex I provided include @github/hotkey (albeit with case-insensitivity), Excalidraw, tinykeys, Mousetrap. A variant appears in ProseMirror keymap, which has 2 bytes golfed off: /Mac|iP(hone|[oa]d)/.

If you're curious, here's your navigator.platform: (Couldn't show it, maybe JavaScript disabled?)