"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

LayerTechnologyPerformance concern
ShellHTML page, a <canvas>, a container elementreserve the canvas size; keep the shell renderable without the game
RuntimeJavaScript engine code (often a framework such as Phaser, PixiJS or a WebAssembly build)parse and compile cost; boot time on the main thread
RenderingCanvas 2D, WebGL, increasingly WebGPUdraw calls, texture memory, frame budget
AudioWeb Audio APIdecode cost, autoplay policy, memory
Assetssprite sheets, texture atlases, audio files, fonts, JSON databytes, number of requests, decode and GPU upload
Inputpointer and touch events, keyboard, gamepadlatency; passive listeners; touch-action
LooprequestAnimationFramestaying 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.

How a browser game's assets are delivered The HTML shell loads a small bootstrap JavaScript runtime, which fetches an asset manifest. From the manifest, code chunks, texture atlases, audio and fonts are fetched in parallel and prioritised per scene. Images are decoded and uploaded to the GPU as textures, then the first playable frame renders and the game loop starts. Only the first scene's assets should gate that moment; later scenes stream in the background. HTML shellcanvas, loader script tagBootstrap JSengine runtime, smallAsset manifestlist of URLs, sizes, hashesCode chunksdeferred game logicTexture atlasessprites packed per sceneAudiocompressed, decoded laterFonts / UIbitmap or web fontsparallel fetches, prioritised per sceneDecode + uploadimages → GPU texturesFirst playable frameloop startsOnly the first scene's assetsgate the first frame. Laterscenes stream in background.
Game asset delivery. Shell → bootstrap runtime → manifest → parallel fetches (code, atlases, audio, fonts) → decode and GPU upload → first playable frame. The loader decides what the first frame waits for.

A well-structured game loads in stages:

  1. 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.
  2. 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 async attribute lets the browser compile it off the main thread; MDN's note on async scripts explains why this matters for large compiled code.
  3. 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.
  4. 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.
  5. 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.
  6. First playable frame. The loop starts. Later scenes stream in the background while the user plays.
Common failure

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

The browser game loop and the per-frame budget A cycle of four steps driven by requestAnimationFrame: input, update, render, wait for the next display refresh. The frame budget is 16.7 milliseconds at 60 hertz, 11.1 at 90 and 8.3 at 120. Update and render must finish inside the budget or a frame is dropped. When the page is hidden the browser throttles requestAnimationFrame, so audio and timers should pause on visibilitychange. Inputtouch, keys, pointerUpdatestate, physics, timersRendercanvas / WebGL drawWaitnext display refreshone tickper refreshDriven by requestAnimationFrame.Advance by elapsed time, not per tick.FRAME BUDGET60 Hz16.7 ms90 Hz11.1 ms120 Hz8.3 msUpdate + render must finishinside the budget, or theframe is dropped.Hidden tab: rAF is throttled.Pause audio and timers onvisibilitychange.
Game loop. Input → update → render → wait, once per display refresh via 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.

  1. Canvas API — MDN Web Docs
  2. Optimizing canvas — MDN Web Docs
  3. WebGL: 2D and 3D graphics for the web — MDN Web Docs
  4. WebGL best practices — MDN Web Docs
  5. WebGPU API — MDN Web Docs
  6. WebGL overview — Khronos Group
  7. Web Audio API — MDN Web Docs
  8. Audio for Web games — MDN Web Docs
  9. Web Audio API specification — W3C
  10. Anatomy of a video game — MDN Web Docs
  11. Efficient animation for web games — MDN Web Docs
  12. Window: requestAnimationFrame() — MDN Web Docs
  13. Web Workers API — MDN Web Docs
  14. OffscreenCanvas — MDN Web Docs
  15. Async scripts for asm.js — MDN Web Docs
  16. Window: devicePixelRatio — MDN Web Docs
  17. Page Visibility API — MDN Web Docs
  18. HTML Living Standard — WHATWG