"HTML5 game" is shorthand for a game that runs inside an ordinary web page using only standard browser features: HTML for the shell, JavaScript for the logic, the Canvas and WebGL APIs for drawing, and the Web Audio API for sound. No plug-in, no app store. The phrase dates from the period when Flash was being retired, and it stuck even though the interesting parts are the JavaScript and graphics APIs rather than HTML itself.
This guide explains what a browser game actually sends over the network and runs on the device, at the level a frontend or infrastructure engineer needs in order to make it load and play well. It does not describe any particular engine or reproduce any game's source code.
The parts of a browser game
| Layer | Technology | Performance concern |
|---|---|---|
| Shell | HTML page, a <canvas>, a container element | reserve the canvas size; keep the shell renderable without the game |
| Runtime | JavaScript engine code (often a framework such as Phaser, PixiJS or a WebAssembly build) | parse and compile cost; boot time on the main thread |
| Rendering | Canvas 2D, WebGL, increasingly WebGPU | draw calls, texture memory, frame budget |
| Audio | Web Audio API | decode cost, autoplay policy, memory |
| Assets | sprite sheets, texture atlases, audio files, fonts, JSON data | bytes, number of requests, decode and GPU upload |
| Input | pointer and touch events, keyboard, gamepad | latency; passive listeners; touch-action |
| Loop | requestAnimationFrame | staying inside 16.7 ms at 60 Hz, or less on faster displays |
Rendering: Canvas, WebGL, WebGPU
The <canvas> element is a bitmap that JavaScript draws into. It offers two families of context. The 2D context (the Canvas API on MDN) exposes paths, images, text and transforms; it is simple and well supported, and for a 2D game with modest draw counts it is often enough. WebGL exposes the GPU through an API modelled on OpenGL ES 2.0 (WebGL 1) and 3.0 (WebGL 2), driven by shaders. Most 2D game frameworks use WebGL under the hood because batching thousands of sprites into a few draw calls is far faster than drawing each one through the 2D context. WebGPU is the successor API with a modern explicit design; MDN lists it as limited availability as of 2026 because it is not yet supported in all widely used browsers, so production games treat it as an optional fast path behind WebGL.
Three canvas facts matter for performance. First, the canvas bitmap's size in device pixels is set by its width and height attributes, independently of its CSS size; on a high-DPI phone a canvas sized to the CSS pixels will look blurry, and a canvas sized to the full device pixel count costs four times the fill rate at a 2× ratio. Games pick a resolution scale deliberately, often less than the full devicePixelRatio on low-end devices. Second, MDN's canvas optimization guidance applies regardless of engine: avoid sub-pixel coordinates, batch state changes, pre-render static layers to an offscreen canvas, and do not scale images on every frame. Third, canvas content is invisible to assistive technology, so the surrounding HTML must carry any information a non-sighted user needs.
Audio
The Web Audio API builds a graph of nodes: sources, effects and a destination. For games the relevant characteristics are low-latency triggering of short sounds, precise scheduling, and the ability to decode compressed files into memory once. Two delivery concerns follow. Decoding is CPU work that should happen during the loading phase, not when the sound first plays. And browsers block audio output until the user has interacted with the page, so the audio context must be created or resumed from inside a tap or click handler; a game that tries to play a start jingle automatically gets silence and sometimes a console warning. MDN's guide to audio for web games covers both.
The loading phase
The loading phase is where most browser games are won or lost on first impression. The question is not how many megabytes the game has in total but how many it needs before showing something playable.
A well-structured game loads in stages:
- Shell. The HTML page renders its own content, including a poster image or a styled placeholder inside the game container with its final dimensions. The page has an LCP candidate and no layout shift before any game code arrives.
- Bootstrap. A small script loads the engine runtime. If the runtime is large, it is a separate file so the browser can cache it across games and sessions. The
asyncattribute lets the browser compile it off the main thread; MDN's note on async scripts explains why this matters for large compiled code. - Manifest. The runtime fetches a list of assets with sizes and hashes, grouped by scene. The loader now knows what the first scene needs and can show real progress.
- Parallel fetch. Code chunks, texture atlases, audio and fonts for the first scene download in parallel. Over HTTP/2 or HTTP/3 the number of files matters less than it did, but the total bytes still do.
- Decode and upload. Images are decoded to bitmaps and uploaded to the GPU as textures; audio is decoded to buffers. This is CPU work and should be spread across frames or moved to a worker so the loading screen stays responsive.
- First playable frame. The loop starts. Later scenes stream in the background while the user plays.
Fetching every asset for every scene before the first frame. The user sees a progress bar for a long time on a slow connection and nothing at all if any single file fails. Stage the manifest and gate the first frame only on the first scene.
Sprite sheets and texture atlases
A sprite sheet packs many small images into one file; a texture atlas is the same idea with a data file that records where each sprite sits. The benefits are fewer HTTP requests, better compression of similar imagery, and, crucially for WebGL, the ability to draw every sprite from the same texture in one batched draw call without switching GPU state. The trade-off is granularity: a change to one sprite invalidates the cache for the whole sheet, and a scene that uses two sprites from a 4096-pixel atlas still pays for the whole atlas in memory. Group atlases by scene, keep them under the GPU's maximum texture size on the devices you support, and version the file name so caches stay correct. The asset guide covers compression formats for atlases.
The game loop and frame timing
requestAnimationFrame. The budget shrinks as refresh rates rise.A browser game draws by asking for a callback before the next display refresh with requestAnimationFrame. Inside the callback it reads input, advances the simulation by the elapsed time, draws the frame and returns. The display refresh rate sets the budget: 16.7 milliseconds at 60 Hz, 11.1 at 90 Hz, 8.3 at 120 Hz. If the callback runs over, the frame is dropped and motion stutters.
Three rules follow. Advance the simulation by measured elapsed time, not by a fixed amount per callback, so the game runs at the same speed on a 60 Hz and a 120 Hz display. Keep the callback inside the budget by batching draws and avoiding allocation in the hot path. And handle the hidden tab: browsers throttle requestAnimationFrame to zero when the page is not visible, so pause audio and timers on visibilitychange rather than letting a backlog of simulation time accumulate.
Because the loop shares the main thread with the rest of the page, it interacts with Interaction to Next Paint. A tap that arrives while a 30 millisecond frame callback is running waits for it. Keeping frames short is both a smoothness and a responsiveness concern. Heavy work such as physics, pathfinding or decoding can move to a Web Worker, and with OffscreenCanvas even rendering can run off the main thread in supporting browsers.
Browser compatibility
Canvas 2D, WebGL 1, Web Audio and the Fullscreen API are available in every current browser. WebGL 2 is widely available. WebGPU is not yet universal. Beyond API availability, the practical compatibility problems are capability limits that vary by device: maximum texture size, available GPU memory, shader precision on older mobile GPUs, and audio decoding formats. Feature-detect, choose a resolution scale and texture tier at start-up, and test on a real low-end phone, not only in a desktop browser with device emulation.
Where the page and the game meet
The host page and the game have to be designed together. The page should reserve the game's box so nothing shifts when it boots; it should serve a poster so there is an LCP element; it should not load the runtime until the container is visible or the user chooses to play; and its own third-party scripts should not compete with the runtime for the main thread. When the game runs in an <iframe>, the frame should be sized with an aspect ratio and the embedded document should be as lean as a standalone page. The mobile UX guide covers how that box should behave on a phone.
Sources
Primary documentation consulted for this guide. Thresholds and API behaviour were checked against these pages on 2026-11-02.
- Canvas API — MDN Web Docs
- Optimizing canvas — MDN Web Docs
- WebGL: 2D and 3D graphics for the web — MDN Web Docs
- WebGL best practices — MDN Web Docs
- WebGPU API — MDN Web Docs
- WebGL overview — Khronos Group
- Web Audio API — MDN Web Docs
- Audio for Web games — MDN Web Docs
- Web Audio API specification — W3C
- Anatomy of a video game — MDN Web Docs
- Efficient animation for web games — MDN Web Docs
- Window: requestAnimationFrame() — MDN Web Docs
- Web Workers API — MDN Web Docs
- OffscreenCanvas — MDN Web Docs
- Async scripts for asm.js — MDN Web Docs
- Window: devicePixelRatio — MDN Web Docs
- Page Visibility API — MDN Web Docs
- HTML Living Standard — WHATWG