How to Make a Browser Game from Scratch and Publish It Online

Himanshu Tyagi
Last updated on Nov 27, 2026

Our guides are based on hands-on testing and verified sources. Each article is reviewed for accuracy and updated regularly to ensure current, reliable information.Read our editorial policy.

Key Takeaways

  • Canvas and Phaser are practical starting points for lightweight 2D browser games.
  • Unity and Godot support more complex projects but require careful web optimization.
  • Use delta time in your game loop to keep movement consistent across different frame rates.
  • Compress assets and load content in stages to reduce initial loading times.
  • Test your game on real desktop and mobile devices before publishing.

A browser game runs from a link. Players open a page, the game loads, and they start playing without installing anything.

That convenience is also the main constraint. Every asset required for your game’s initial load adds to the time players spend waiting before they can start playing. On a phone with a weak connection, that wait is where many players leave.

So learning how to make a browser game is as much about delivery as it is about design. The engine you pick and the way you package assets can decide whether a player waits two seconds or closes the tab after twenty.

This guide covers the full process, from choosing an engine and writing a basic game loop to shrinking the build, testing it on real devices, and putting it online.

What You Need Before You Start

You don’t need specialized hardware. Browser games are built with web technologies, mainly HTML, JavaScript, and a rendering layer such as the Canvas 2D API or WebGL. Any recent computer with a code editor and a modern browser is enough for basic 2D work.

Plan for these basics:

  • A code editor, such as Visual Studio Code, or the editor bundled with your engine.
  • A local web server for testing, since browsers restrict some requests made from pages opened directly from disk.
  • At least one desktop browser and one phone for testing.
  • A deliberately small scope. A single mechanic that works well is a better first project than a large game that never ships.

Step 1: Choose an Engine or Framework

Your first decision is technology. Some tools were built for the web from the start, while others treat it as one export target among many.

Engine or Framework Language Best Suited For Notes
Canvas API (no engine) JavaScript Very small 2D games and learning projects No additional engine runtime to download
Phaser JavaScript or TypeScript 2D arcade, platform, and puzzle games Designed specifically for the browser
Construct 3 Visual event sheets, optional JavaScript Fast 2D prototyping with little code Exports HTML5 directly
Godot GDScript 2D and 3D games that may also ship on desktop Web export bundles the engine runtime
Unity C# 3D games and teams already using Unity Heavier runtime that needs careful optimization

For a first project, a lightweight JavaScript framework keeps the build small and lets you see changes by refreshing the page. If you want to make a 3D game or already know C#, Unity’s web build target is a reasonable path, as long as you plan for its larger download from the first day.

Unity Web Builds

If you choose Unity, check your development machine first. The editor needs a supported 64-bit operating system and enough memory to handle asset imports, and our breakdown of the minimum and recommended specs for running Unity covers each desktop platform.

Install the Web Build Support module through Unity Hub. Once the editor runs, switch the build target to Web under File > Build Profiles in Unity 6, or select WebGL in the Build Settings window in older versions.

Keep early scenes simple, because additional textures, models, and plugins can increase the size of your final build.

Step 2: Build the Core Game Loop

Every real-time game runs a loop that reads input, updates the game state, and draws the result. In the browser, the standard way to schedule that loop is requestAnimationFrame(), which asks the browser to call your function before the next screen repaint.

Here is a minimal keyboard-controlled movement prototype you can save as index.html:

code
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My Browser Game</title>
  <style>
    html, body {
      margin: 0;
      height: 100%;
      background: #111;
      overflow: hidden;
    }

    canvas {
      display: block;
    }
  </style>
</head>
<body>
  <canvas id="game"></canvas>

  <script>
    const canvas = document.getElementById("game");
    const ctx = canvas.getContext("2d");

    const player = { x: 50, y: 50, size: 24, speed: 200 };
    const keys = {};

    function clampPlayer() {
      player.x = Math.max(
        0, Math.min(player.x, canvas.width - player.size)
      );

      player.y = Math.max(
        0, Math.min(player.y, canvas.height - player.size)
      );
    }

    function resize() {
      canvas.width = window.innerWidth;
      canvas.height = window.innerHeight;
      clampPlayer();
    }

    window.addEventListener("resize", resize);
    resize();

    const arrows = [
      "ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp"
    ];

    window.addEventListener("keydown", (e) => {
      if (arrows.includes(e.key)) {
        e.preventDefault();
        keys[e.key] = true;
      }
    });

    window.addEventListener("keyup", (e) => {
      keys[e.key] = false;
    });

    window.addEventListener("blur", () => {
      for (const key of arrows) keys[key] = false;
    });

    let last = performance.now();

    function loop(now) {
      const dt = Math.min((now - last) / 1000, 0.05);
      last = now;

      let dx = Number(!!keys.ArrowRight) -
               Number(!!keys.ArrowLeft);

      let dy = Number(!!keys.ArrowDown) -
               Number(!!keys.ArrowUp);

      const length = Math.hypot(dx, dy);

      if (length > 0) {
        player.x += (dx / length) * player.speed * dt;
        player.y += (dy / length) * player.speed * dt;
      }

      clampPlayer();

      ctx.fillStyle = "#111";
      ctx.fillRect(0, 0, canvas.width, canvas.height);

      ctx.fillStyle = "#4ade80";
      ctx.fillRect(
        player.x, player.y, player.size, player.size
      );

      requestAnimationFrame(loop);
    }

    requestAnimationFrame(loop);
  </script>
</body>
</html>

To run the example locally, open a terminal in your project directory. If you have Python 3 installed, start a local web server with this command:

code
python -m http.server 8000 --bind 127.0.0.1

Depending on your operating system, you may need to use python3 instead of python.

Open http://127.0.0.1:8000/ in your browser. You should see a green square on a dark background that you can move using the arrow keys.

You can also use an HTML viewer and editor to preview the prototype directly in your browser. Click inside the preview before using the arrow keys.

The dt value, or delta time, measures the seconds since the last frame. Multiplying movement by it helps keep the player’s speed consistent across different refresh rates. Capping delta time also prevents large jumps after switching away from the browser tab.

The movement vector is normalized so that diagonal movement is not faster than horizontal or vertical movement. The boundary checks keep the player inside the canvas.

Engines like Phaser and Godot run their own game loops for you, but the structure underneath is similar. Understanding it makes engine bugs much easier to diagnose.

This example provides the foundation for a game rather than a finished one. From here, you can add obstacles, collectibles, scoring, collision detection, and a win or lose condition.

Add touch input early. Many players open browser games on phones, where there is no physical keyboard, and retrofitting touch controls into a finished game is harder than designing for them from the start.

Step 3: Keep the Build Small

Loading is the first part of your game anyone experiences. A smaller build can reach the first playable frame sooner, especially on mobile data.

Much of the weight in asset-heavy games comes from assets rather than your own game code:

Asset Type Common Problem What to Do
Images and sprites Source files larger than needed for their display size Export at appropriate resolutions, pack sprites into atlases, and use WebP where supported
Audio Uncompressed WAV files Convert to MP3 or Ogg Vorbis where supported, at a bitrate that still sounds clean
3D models Dense meshes and large textures Reduce polygon counts and texture resolution
Code Debug builds and unused libraries Ship an optimized release build and remove development tools
Fonts Full character sets Subset fonts to the characters your game needs, including supported languages

For browser games that load image files directly, a JPG to WebP converter can help reduce the file size of backgrounds and other JPEG assets. Compare the resulting file size and visual quality before replacing your originals.

Similarly, if you are building a small game in plain JavaScript without a build system, a JavaScript minifier can reduce the size of standalone script files. Test the minified version before publishing.

Compress the Build

Compression shrinks what travels over the network. Unity offers two compression formats: gzip and Brotli. Gzip is generally faster to compress, while Brotli typically produces smaller files. Modern browsers support both formats, but you should serve Brotli-compressed builds over HTTPS for compatibility.

For the browser to unpack those files natively as they arrive, the server must send each one with a matching Content-Encoding header, such as gzip or br. If you can’t change server settings, Unity’s decompression fallback adds a JavaScript decompressor to the build, at the cost of a larger loader.

Important: Always measure a release build. Unity does not compress development builds through its build compression settings, so their size says little about what players will actually download from an optimized deployment.

Load in Stages

Not everything needs to arrive before the game starts. Load the menu and first level up front, then fetch later levels, music, and optional content in the background while the player is already playing.

A short loading bar also helps. A visible sense of progress makes a few seconds of waiting feel shorter than a blank screen.

Step 4: Test in Real Browsers and Devices

A game that runs smoothly on your development machine can stutter on a three-year-old phone. Test early and keep testing as the build grows.

Unity 6 supports compatible desktop and mobile browsers with WebGL 2.0 and WebAssembly support. Its web browser compatibility documentation lists the supported browsers and operating systems.

Older versions, including Unity 2022.3, do not officially support mobile devices for WebGL builds. JavaScript frameworks may have less demanding browser requirements, depending on their rendering technology and the features you use.

Work through this checklist before release:

  1. Run every major browser: Chrome, Firefox, Safari, and Edge on desktop.
  2. Test on real phones: An older Android device and an iPhone can show performance and input problems that emulators hide.
  3. Throttle the network: Use your browser’s developer tools to simulate a slow connection and watch the loading time.
  4. Rotate and resize: Check portrait and landscape layouts and resizing of the browser window.
  5. Check audio: Browsers often block sound until the player interacts with the page, so start or resume audio after the first click or tap.
  6. Switch browser tabs: Check that the game resumes correctly without unexpected movement or stuck controls.

Step 5: Publish Your Browser Game

Once the game is stable, you need somewhere for players to find it. Most developers choose between open indie platforms, curated web game portals, and their own website.

Open Indie Platforms

itch.io lets developers upload an HTML5 game as a ZIP file with an index.html entry point. Its standard HTML5 upload requirements specify a maximum of 1,000 extracted files, 500 MB of total extracted content, and 200 MB for any individual extracted file.

The platform’s HTML5 game publishing documentation also flags two common causes of broken uploads. File names on its servers are case-sensitive, and absolute paths can fail because each game is hosted in a subdirectory, so reference your game assets with relative paths.

Curated Web Game Portals

Curated portals review submissions and usually set much tighter technical targets than open upload sites. On Poki.com, for example, the developer guide recommends keeping the initial game download within 5 MB and the total size within 8 MB.

Games made with engines such as Phaser, Godot, Defold, GDevelop, or Unity can integrate with the platform through its Poki SDK. Developers must also meet the platform’s technical and quality requirements before their games can go live.

Those size targets sit far below what some open platforms accept. They are a useful benchmark for lightweight browser games, whether or not you ever submit to a portal.

Self-Hosting

Publishing on your own domain gives you more control over the page, the URL, and monetization. It also makes you responsible for HTTPS, compression headers, and caching, which managed publishing platforms generally handle for you.

To publish a simple HTML5 game on your own website, upload the production files to your web hosting service, make sure the entry page is accessible, and test the public URL in a browser.

The other trade-off is discovery. A self-hosted game does not automatically benefit from an established gaming platform’s audience. You may need to attract players through search engines, online communities, referrals, and social sharing.

Some developers publish on a platform first and keep a self-hosted version as a second home. Before doing this, check the platform’s licensing, distribution, and exclusivity terms.

Final Thoughts

The fastest route to a finished browser game is a small one. Build a single mechanic in the tool you’re most comfortable with, measure the release build size before you add more content, and test on a slower phone as well as your development machine.

From there, each new feature becomes a trade-off you can measure against loading time. That habit, more than any engine choice, can help you build browser games people keep playing instead of closing before the first level loads.

Himanshu Tyagi

About Himanshu Tyagi

At CodeItBro, I help professionals, marketers, and aspiring technologists bridge the gap between curiosity and confidence in coding and automation. With a dedication to clarity and impact, my work focuses on turning beginner hesitation into actionable results. From clear tutorials on Python and AI tools to practical insights for working with modern stacks, I publish genuine learning experiences that empower you to deploy real solutions—without getting lost in jargon. Join me as we build a smarter tech-muscle together.

Comments

Comments are provided by Disqus, which sets cookies and processes data under its own privacy policy.

Free Online Tools

Try These Related Tools

Free browser-based tools that complement what you just read — no sign-up required.

Keep Reading

Related Posts

Explore practical guides and fresh insights that complement this article.

Why Do Regression Testing Issues Happen and How Can Teams Prevent Them?
Programming

Why Do Regression Testing Issues Happen and How Can Teams Prevent Them?

Regression testing problems cost development teams far more than late nights and blown deadlines. The Consortium for Information & Software Quality (CISQ), in a report co-sponsored by Synopsys, put the cost of poor software quality in the US at roughly $2.41 trillion, with cybercrime, technical debt, and supply chain failures driving most of that number. […]

Building an Invoice Automation Pipeline: OCR, Webhooks, and Approval Logic
Programming

Building an Invoice Automation Pipeline: OCR, Webhooks, and Approval Logic

A finance team’s request usually sounds simple: cut down on manual invoice entry. In practice, that request splits into five separate engineering problems: getting invoices into one place, turning documents into structured data, matching that data against a purchase order, routing it through approval, and catching anything that stalls. None of these problems is hard […]

As featured on

CodeItBro - Free dev tools + practical guides to help you ship faster | Product HuntCodeItBro - Free Online Developer Tools badgeCodeItBro badgeFeatured on neeed.directory