HTML5 game publishing

Dense Tap Targets on Phones: Hit Testing for Puzzle Boards

Target sizes, pointer events, touch-action, nearest-target picking with a tolerance, visible feedback, screen edges and double input, so crowded boards stop feeling unfair.

PlayKovo Team4 min read
Games currently available on PlayKovo. Open a title to see its current listing.

Puzzle boards that need precise taps, like arrow grids, hex tiles, sort puzzles and block removal, share one problem on phones: fingers are bigger than the thing they are trying to hit. A tap that lands one pixel off the intended arrow either does nothing or hits the wrong one, and the player blames the game. This post covers how to make dense tap boards reliable on touchscreens: sizing, hit testing, forgiving targeting, and the input events that avoid common browser behaviour.

How big a target needs to be

Platform guidelines give a rough floor. Apple's Human Interface Guidelines recommend a minimum tap target of 44 by 44 points, and Material Design recommends at least 48 by 48 density-independent pixels. A 44 pt target is roughly 7 to 9 mm on a typical phone. If your board has a 12 by 12 grid on a phone 360 CSS pixels wide, each cell is about 30 px, below the guideline. You will not always be able to make cells larger, but you can make hit areas larger than the visible shapes.

Three ways to handle a board that is physically too dense:

  1. Limit the grid size on small screens. Generate smaller boards for narrow viewports.
  2. Let the board scroll or zoom. Pinch zoom and pan on big boards, with cells at a comfortable size.
  3. Make hit areas forgiving. Explained below.

Use pointer events

Pointer events unify mouse, touch and pen input, and avoid the duplicated events you get when handling both touchstart and mousedown. One handler works everywhere:

canvas.addEventListener('pointerdown', e => {
  e.preventDefault();
  const r = canvas.getBoundingClientRect();
  const x = (e.clientX - r.left) * (canvas.width  / r.width);
  const y = (e.clientY - r.top)  * (canvas.height / r.height);
  handleTap(x, y);
});

Always convert from page coordinates to canvas coordinates using the canvas's displayed size, since CSS scaling and device pixel ratio make them differ. The conversion above handles any scale. If your canvas is sharp on high-density screens, that is covered in canvas resolution and devicePixelRatio.

Stop the browser from interfering

Touch browsers try to be helpful: double-tap to zoom, scroll, pull to refresh. All of these steal taps from a game. Disable them on the play area with CSS:

#board {
  touch-action: manipulation;   /* or: none, if you handle pan/zoom yourself */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

touch-action: manipulation keeps panning and pinch zoom but removes the double-tap-to-zoom delay and behaviour. Use none if you implement your own zoom and pan. Also prevent text selection and the grey tap highlight, which look like glitches on a game board.

Forgiving hit testing

The visible size of a shape is not the size of its tap target. A slim arrow drawn 6 px wide can have a hit area of 30 px around its centre line. A simple approach: find the nearest target within a tolerance radius of the touch point, instead of requiring the point to fall inside the shape.

function pick(x, y, targets, tolerance = 24) {
  let best = null, bestD = tolerance * tolerance;
  for (const t of targets) {
    const d = distToShape(x, y, t);     // 0 if inside
    if (d < bestD) { bestD = d; best = t; }
  }
  return best;
}

Two rules keep it fair:

  • Always take the nearest, never the first. If two shapes are within tolerance, the closer one wins. Otherwise the result depends on draw order.
  • Tolerance should shrink for small boards and grow for dense ones. Tie it to the cell size, such as 60% of a cell, rather than a fixed pixel number.

Show what was hit

Even with good targeting, players want proof of which target received the tap. Immediate visual feedback does most of the work:

  • A brief highlight on pointerdown, before the action resolves.
  • A small scale pulse or flash on the chosen shape.
  • For mistakes, shake the shape the player tapped, not a generic error banner.

This also helps you catch targeting bugs in playtests. If testers say "it did the wrong one", you will see exactly what the game thought they tapped. See game feel and juice for browser games for more on feedback.

Handle the edges of the screen

Targets near screen edges are difficult on phones. System gestures, rounded corners and notches interfere. Practical measures:

  • Keep a margin of at least 8 to 12 px between the board and the viewport edge.
  • Respect safe areas with env(safe-area-inset-*) padding, as covered in mobile browsers, touch controls and safe areas.
  • Put frequently used buttons (undo, hint, restart) away from the extreme bottom edge, where swipe-up gestures live on many phones.

Prevent accidental double input

Fast players tap twice, and some devices generate two events. If a tap removes an arrow and the second tap lands on the arrow underneath, the player loses a move they did not intend. Two defences:

  1. Ignore input while a move animation plays, or queue it explicitly.
  2. Store the time of the last accepted tap and ignore another within about 80 ms at the same position.

For input handling across keyboard, touch and gamepad, see building an input layer.

Test on real hands

Emulators click with perfect precision. They tell you nothing about fat fingers. Test on at least one small phone and one tablet, with real thumbs, in both hands. A cheap test: ask someone who has never seen the game to play five levels while you only watch where they miss. Misses cluster around a few problem spots, and those are what you adjust. Our guide to cheap playtesting explains how to run such sessions.

We use optional cookies for site analytics and site advertising. You can change your choice later. Privacy policy.