Test store. Prices are the planned list prices stored as test data, license terms are drafts, and payments go to a Stripe test-mode account. No real money moves.

HTML Game Code: Free Games You Can Copy, Paste and Play

Every game here is complete HTML game code in one file: HTML, CSS and JavaScript, no libraries. Pick a game, press Copy code, save it as a .html file and open it in your browser, or paste it into the runner below. All of it is free to use under the MIT license, including in commercial projects.

Free games with full code

HTML game code runner

Paste any single-file HTML game and press Run. It runs in a sandboxed frame with no access to this site.

Paste any single-file HTML game and press Run. It runs in a sandboxed frame with no access to this site.

How to use HTML game code

Copy-and-paste HTML game code works because a browser already contains everything a small game needs: a drawing surface (the <canvas> element), a clock (requestAnimationFrame) and input events for keys, mouse and touch. A single .html file can hold all three parts:

  1. HTML: a <canvas> to draw on, plus a <title> and a viewport tag so it scales on phones.
  2. CSS: a few lines that make the canvas fill the screen and stop the page from scrolling during play.
  3. JavaScript: the game itself: state, a loop that updates and draws it, and listeners for input.

To run any game on this page, copy the code into a text editor, save it with a .html extension and double-click the file. No server, install or build step is involved, which is why these simple HTML5 game code examples make good starting points for learning, class projects and game jams.

HTML vs HTML5 game code

People search for "HTML game code" and "HTML5 game code" for the same thing. Strictly, HTML only describes the page; the game logic is JavaScript, and the drawing uses the HTML5 canvas API. When you see "HTML5 games", read "games that run in a browser without plugins", which replaced Flash games after 2020. Our guide What are HTML5 games? explains the technology in plain terms.

What makes these code examples different

Most free HTML games code you find online is either a fragment that needs other files, or a minified build nobody can read. Every game here follows the same rules:

  • Complete: one file, nothing to download or install, and it runs offline.
  • Readable: plain JavaScript with comments, usually 150 to 350 lines.
  • Works on phones: touch or swipe controls and a canvas that resizes with the screen.
  • Explained: each game has a tutorial that walks through the loop, input, collisions and drawing.
  • Tested: we play every game in a sandboxed frame at desktop and phone sizes before publishing it.
  • Free: MIT-licensed, so you can change it and ship it.

Simple games to start with

If you're new to game code, start with Snake and Pong: they teach the game loop, keyboard input and collision in under 200 lines. Breakout and the memory game add more objects and game states. The platformer, tower defense and match-3 examples show the patterns bigger games are built on, like gravity, pathing and grid logic.

Classic arcade ideas without their own page yet, like a Pac-Man-style maze chase, a fish-eating game or an avoider, use the same building blocks: start from the maze game or the space shooter and change the rules.

From free code to a finished game

Free game code teaches the core loop. A game you can sell, put on a portal or hand to a client needs much more: levels, original art and sound, saves, ad and portal SDK hooks, localisation, testing on real devices and documentation. That's what our catalog is for: every game ships as a buildable TypeScript project you can reskin and launch.

Browse HTML5 games with source code

To build your own from scratch instead, follow how to make an HTML5 game, or see the free and open-source HTML5 games collected from GitHub.

Frequently asked questions

Is this HTML game code really free?

Yes. Every game on this page is released under the MIT license. You can copy, change and use the code in personal and commercial projects as long as you keep the license line at the top of the file.

Can I copy and paste these games into my website?

Yes. Upload the .html file to your site and link to it, or show it inside a page with an <iframe>. Our guide to embedding an HTML5 game in a website covers WordPress, Wix and Google Sites.

How do I run HTML game code without saving a file?

Paste it into the code runner on this page and press Run. It runs in a sandboxed frame, so the code can't reach this site, your cookies or your storage.

Do I need to know JavaScript to use these games?

Not to play or host them. To change how a game plays, a little JavaScript helps: start with the settings at the top of each file (speeds, sizes, colours), then follow the tutorial on that game's page.

Can I download the game code as a zip?

Each game is a single file, so there's nothing to unzip: press Download .html on the game's page. For bigger projects with art, levels and tests, see our HTML5 games with full source code.