Feature Library

Menus by gamepad

0.04 CPU ms
A still of the Menus by gamepad demo
Still
The live demo starts when it’s in view.A real gamepad, or the on-screen pad (hold a direction to repeat) · keys: arrows d-pad, Z A, X B, Q and E the shoulders, P Start

A game’s menus driven by a gamepad on top of ordinary focus.

A game’s menus driven by a gamepad on top of ordinary focus: A presses the focused control, the d-pad or the left stick moves focus to the nearest control in that direction (so a list, a grid of tiles and a ring of round buttons all work without any layout table), a held direction repeats like a key, B goes back, LB and RB step through tabs, Start pauses. Radios, tabs and sliders take the arrows themselves on their own axis. Nothing draws: the controls stay plain buttons, so keyboard, pointer and screen reader keep working beside the pad, and an on-screen or keyboard pad can drive it the same way.

See it live in Swarm run, the 2D action kit’s game →

What it costs a frame

0.04 ms
GPU
not used
CPU, median
0.04 ms
CPU, 95th pct
0.32 ms
Draw calls
0
Weight
Light

Measured 21 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.04–0.04 ms). What ran: The bench drives the on-screen pad itself: a move every 18 frames round the ring, list and grid (each move reads the layer’s controls and their boxes), and a tab switch now and then. No gamepad is connected headless. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
29.52 ms
1% low ?
29 fps
Varies by ?
±5.24 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.02 ms34.50 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
29.52 ms
p95 ?
31.45 ms
p99 ?
32.44 ms
Slowest ?
39.88 ms
Mean ?
26.56 ms
Standard deviation ?
5.24 ms
1% low ?
29 fps
0.1% low ?
25 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 0.5 / 3.0 ms

Input

Interactions ?
6
Input to paint ?
5.3 ms, worst 13.7
Longest handler ?
under 16 ms

Memory

JavaScript heap ?
33.4 → 34.2 MB
Growth ?
+0.78 MB

Browser

JavaScript a frame ?
0.19 ms
All tasks a frame ?
0.51 ms
Layout / style ?
0.03 / 0.05 ms
Main thread busy ?
2%

Garbage collection

Collections ?
0 (0 minor, 0 major)
Pauses ?
0.0 ms in all, longest 0.0

What it needs

Renders with
DOM and CSSPlain DOM and CSS: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages
With an agent
install("pad-menus")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. Pause, settings and title menus in a browser game played with a controller
  2. A radial menu or a grid of tiles picked with the stick
  3. Tabs in a settings screen changed with the shoulder buttons
  4. A couch or TV app driven by a pad or a remote
  5. A kiosk with a hardware joystick

Pitfalls, in brief

  1. The Gamepad API has no button events: call poll() once a frame, also while the game is paused (that is when the menus are up).
  2. Give layer() the top dialog’s panel while a dialog is open and null while playing, so the pad never moves focus behind a modal and play keeps the pad to itself.
  3. B dispatches an Escape keydown on the focused element by default: accessible-dialog closes on it.
  4. Focus is the pad’s cursor, so it must always show: programmatic focus after a pointer click may not match :focus-visible.
  5. Spatial movement reads the controls’ boxes (getBoundingClientRect) on each move, not each frame.
3 more in brief
  1. A radio group, a tab list or a slider takes left and right (or up and down when aria-orientation is vertical) as arrow keys; the other axis leaves it.
  2. Use the standard mapping’s indices (A 0, B 1, LB 4, RB 5, Start 9, d-pad 12 to 15); a pad without mapping "standard" may number them differently: pass buttons.
  3. An on-screen pad must not take focus itself: its buttons are out of the tab order and prevent the pointerdown default, or every press would move focus out of the menu.
8 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From another of the maker’s apps. Fully custom code.

gamepadcontrollermenusspatial navigationfocuskeyboardaccessibilitydialoggame uidomno dependencies

Near it in the frame