Controller support in a browser game used to be a nice-to-have. Now plenty of players open a web game on a laptop with a pad already paired, or on a TV browser, or on a handheld PC, and expect it to just work. The Gamepad API makes the basics straightforward, but there's a gap between "the pad moves the character" and "this feels like a proper controller-supported game".

This is the checklist I'd run through before telling players an HTML5 game supports controllers.

1. Don't wait for an event that may never fire

Browsers generally don't expose a gamepad to a page until the player presses a button or moves a stick while the page has focus. That's a privacy measure, and it means a pad that was connected before the page loaded can look "missing".

  • Listen for gamepadconnected and gamepaddisconnected, but also poll navigator.getGamepads() in your game loop.
  • On the title screen, show a short prompt such as "Press any button on your controller" rather than assuming no pad is present.
  • Serve the game over HTTPS. Current browsers restrict the Gamepad API to secure contexts, so a test build on plain HTTP can behave differently from production.

2. Poll once per frame, from a fresh snapshot

The Gamepad objects you get back are snapshots in some browsers, so holding on to one from an earlier frame can leave you reading stale values.

function readPads() { const pads = navigator.getGamepads(); for (const pad of pads) { if (!pad) continue; // empty slots are null handlePad(pad); } } function frame() { readPads(); update(); render(); requestAnimationFrame(frame); } requestAnimationFrame(frame); 

Track button state yourself (previous frame vs current frame) so you can tell "just pressed" from "held". Menus need the first; movement needs the second.

3. Check mapping before trusting button indices

When pad.mapping === "standard", the browser has mapped the device to the standard layout: face buttons, shoulders, triggers, sticks and the d-pad all sit at predictable indices. When mapping is an empty string, it hasn't, and index 0 might be anything.

  • Use the standard layout as your default for pads that report it.
  • For unmapped devices, offer an in-game remapping screen rather than guessing.
  • Show button prompts based on what you actually know. If you can't tell whether it's an Xbox-style or PlayStation-style pad, neutral prompts ("bottom face button") beat wrong ones.

4. Add deadzones and treat triggers as analogue

Sticks rarely rest at exactly zero, so a small amount of drift will move a character or scroll a menu on its own.

  • Apply a radial deadzone to each stick (start somewhere around 0.15 to 0.2 and tune it on real hardware), then rescale the remaining range so movement still reaches full speed.
  • Read triggers from buttons[i].value, not just pressed. They're analogue on most pads, and some games want a threshold rather than any touch.

5. Make every menu navigable without a mouse

This is where most browser games fall down. The gameplay works on a pad, but the pause menu, settings screen or "play again" button needs a click.

  • Give every screen a focused element on open, with a clearly visible focus highlight.
  • Map the d-pad and left stick to focus movement, with a short repeat delay so a held stick doesn't race through the list.
  • Keep confirm and back consistent across every screen, and make back always do something sensible.
  • If you use HTML for menus, keep DOM focus and your own focus state in sync so keyboard and pad players aren't fighting each other.

6. Handle hot-plugging and multiple pads mid-session

Players unplug pads, batteries die and Bluetooth drops.

  • On gamepaddisconnected during play, pause the game and show a "reconnect your controller" message rather than letting the player die.
  • Identify pads by index while they're connected, and decide what happens when a second pad appears: ignore it, offer local co-op, or let either pad control player one.
  • Don't throw away the player's input method choice when a pad disconnects. Fall back to keyboard prompts until a pad is back.

7. Test on the browsers and devices your players actually use

Gamepad behaviour still differs between browsers and operating systems: which pads get the standard mapping, how triggers report, whether rumble (vibrationActuator) is available. Treat vibration as an optional extra and feature-detect it.

A small test matrix goes a long way: one Xbox-style and one PlayStation-style pad, on Chrome, Firefox and Safari, on Windows and macOS, plus any TV or handheld browser you're targeting.

Wrapping up

None of this is complicated, but it adds up to the difference between "technically supports controllers" and a game that pad players recommend. It pairs well with other features that bring players back to a web game, like the daily modes we covered in building a daily challenge mode for an arcade game.

If your team is short on browser game expertise, studios offering HTML5 game development services can help with controller support, performance and cross-browser testing so your game behaves the same on every screen.