Designing HTML5 Games That Work on Any Phone
Building an HTML5 game that looks and plays well on desktop is relatively easy. Making that same game play well on a phone is a different kind of problem entirely. Touch is not mouse. Screens are small and come in a hundred different aspect ratios. Users will rotate their device mid-game. The browser URL bar might suddenly appear and shrink the viewport by 80 pixels. If you do not plan for these realities from the start, your game works in Chrome on your laptop and nowhere else.
Here are the practical rules we follow when we build games for this site.
1. Touch targets must be at least 44 CSS pixels
Apple's Human Interface Guidelines specify a 44-point minimum tap target. Google's Material Design uses 48dp. The reasoning is physical: average adult fingertips cover an oval roughly 10–14 mm across, and tappable elements smaller than 7–10 mm cause frequent misses. Any button, cell, or on-screen control smaller than 44 CSS pixels will frustrate at least some users.
In practice this means Minesweeper cells look large on mobile even though they look "right" on desktop. Tic Tac Toe cells get explicit min-height values. On-screen directional pads in Snake are 56 pixels. This is rarely aesthetically ideal, but it is functionally required.
2. Use viewport-relative units carefully
The vw and vh units look promising for mobile layouts but have quirks. On iOS Safari, 100vh includes the area behind the bottom toolbar, which can cause content to be hidden. The modern fixes are 100svh (small viewport height, excluding dynamic chrome) and 100dvh (dynamic viewport height, which adjusts as chrome appears and disappears).
.game-full { height: 100svh; } /* Safe on iOS */
.game-dynamic { height: 100dvh; } /* Adjusts live */
3. Prevent accidental scroll and pinch-zoom during play
When users swipe in 2048 or drag a paddle in Breakout, they do not want the page to scroll. They also do not want pinch-zoom triggering on double-tap. The solutions:
/* Prevent touch actions on the game surface */
.game-canvas { touch-action: none; }
/* Prevent selection interfering with drags */
.game-canvas { user-select: none; -webkit-user-select: none; }
Combine these with e.preventDefault() on touch events that manipulate the game, and your swipe controls will feel native.
touch-action: none is the single most important CSS rule for a mobile HTML5 game. Without it, every swipe also triggers page scroll, and the experience feels broken.
4. Scale canvas for device pixel ratio
A canvas drawn at 400×400 CSS pixels on a 3x-density iPhone display is actually 1200×1200 physical pixels. Drawing at the default 1x DPR produces visible blur. The fix is to set canvas internal dimensions to CSS size multiplied by device pixel ratio, then scale the context:
const dpr = window.devicePixelRatio || 1;
canvas.width = displaySize * dpr;
canvas.height = displaySize * dpr;
ctx.scale(dpr, dpr);
5. Handle rotation and resize
Users will rotate their phones. Canvas-based games need to rerender correctly at the new size. The simplest solution is to listen for resize and orientationchange events and rebuild the layout. Keep game logic decoupled from rendering so a resize does not corrupt state.
6. Avoid hover-dependent interactions
Touch devices do not have hover. If your game relies on a tooltip that appears on mouse-over, it will be invisible on mobile. Use an explicit tap or long-press instead, and always provide the information elsewhere (labels, always-visible help text, toolbar icons).
7. Test on actual phones
Browser devtools emulate mobile layouts but do not simulate real touch latency, finger occlusion of the screen, or the bottom chrome that iOS Safari adds mid-game. The only way to verify a game is genuinely mobile-friendly is to run it on real hardware. We test on at least three physical devices (iPhone SE, mid-range Android, and iPad) before publishing.
8. Gracefully handle the browser chrome
Mobile browsers hide and show address bars based on scroll. This changes the available viewport mid-game. Design so the critical game area never overlaps a region the chrome will occupy. Use safe-area-inset properties on iOS to respect the notch.
These eight rules cover roughly 90% of the mobile-compatibility work for a casual HTML5 game. Applied consistently, they produce games that play well on any phone from a 2018 iPhone SE to a 2024 flagship Android. You can see the results throughout our games library.