Every game we've built uses HTML5 Canvas. Not WebGL (overkill for 2D), not SVG (too slow), not DOM (unpredictable). Canvas is the sweet spot. Here's why. Every time.
Canvas vs DOM: The Frame Budget
Here's the key: DOM triggers layout and paint cycles on every style change. Every. Single. One. Even with CSS transforms (which are GPU-accelerated), modifying more than 20-30 DOM elements per frame causes jank on mobile. Canvas gives you a pixel buffer where you control every draw call.
For Snake Arena with 50+ grid cells moving simultaneously, DOM would struggle at 30fps on mid-range devices. Canvas handles it at 60fps because there's no layout calculation — just pixel drawing. The tradeoff is more code, but the frame budget is worth it.
Canvas vs. DOM: Rendering Performance
For games that need 60fps rendering, the Canvas API is the only viable option. The DOM was designed for document layout, not real-time animation. Each DOM element triggers the browser's layout and paint pipeline, which calculates positions, sizes, and styles for the entire page before rendering. Even a game with 20 DOM elements can trigger 50ms+ of layout calculation per frame when elements move. Canvas bypasses this entirely — it draws pixels directly to a bitmap.
Memory and Object Management
In DOM-based games, each element is an object that the browser must track, style, and reflow. Memory usage grows linearly with the number of elements. With Canvas, the developer controls exactly what gets drawn and when, with no hidden overhead. A game with 100 animated sprites might use 50MB of DOM-related memory but only 5MB of Canvas-allocated memory. For mobile devices with limited RAM, this difference can determine whether the game runs smoothly.
When DOM Gaming Makes Sense
DOM-based games are not always worse. For turn-based games, card games, puzzle games with static layouts, and games that primarily respond to clicks rather than continuous animation, the DOM offers advantages: built-in accessibility (screen readers can navigate DOM elements), automatic text rendering with full CSS styling, and simpler event handling. The key is matching the rendering approach to the game's interaction model.
Canvas Specifics: How We Optimize
Canvas optimization comes down to minimizing state changes and draw calls. Each fillStyle or strokeStyle change forces the browser to flush the drawing buffer, costing roughly 0.2ms. A naive render loop that sets fillStyle before drawing each of 100 shapes wastes 20ms per frame — more than the entire 16.67ms budget. Our games batch draws by color: group all rectangles, set fillStyle once, draw all of them. This optimization alone reduces render time by 40-60%. We also use requestAnimationFrame with delta-time calculations rather than fixed timesteps.
Accessibility Considerations
The Canvas API's accessibility gap is its most significant drawback. Canvas content is invisible to screen readers because it renders as a single bitmap rather than accessible DOM elements. A DOM-based game can provide semantic HTML, ARIA labels, keyboard navigation, and screen reader announcements. A Canvas-based game provides none of these by default. Gerk Games bridges this gap by overlaying transparent DOM elements on top of the Canvas for interactive controls, providing ARIA descriptions of game state, and ensuring all game functions are available through keyboard navigation. These accessibility additions add roughly 15% to development time but ensure the games are playable by users with visual impairments who rely on screen readers.
Development Speed Considerations
Canvas-based game development is slower than DOM-based development for certain types of interactions. Building a button in the DOM takes one line of HTML and a few lines of CSS. Building the same button on Canvas requires writing custom hit-testing code, managing hover states manually, handling focus and blur events, and rendering the button texture every frame. For this reason, Gerk Games uses a hybrid approach: the game canvas handles all gameplay rendering, while UI elements (buttons, menus, score displays) are overlaid as DOM elements on top of the canvas using absolute positioning. This hybrid approach captures the performance benefits of Canvas for real-time rendering while maintaining the development speed of DOM for static and interactive UI elements.