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
- 2048 Game in HTML5: Full JavaScript Code and Tutorial
Play a 2048 sliding-tile puzzle built with HTML5 canvas, then copy the free code and learn the slide and merge rules, animations, swipes and game over.
- Board Games in HTML5: Tic-Tac-Toe Code, Plus How Chess and Ludo Work
Play tic-tac-toe with an unbeatable AI on an HTML5 canvas, copy the free code, and learn how chess, ludo and other board games are structured.
- Breakout (Brick Breaker) Game in HTML5: Full Code and Tutorial
Play a brick breaker made with HTML5 canvas, then copy the free code and learn the bouncing ball physics, brick collisions, levels and lives step by step.
- Card Game in HTML5: Golf Solitaire Code and Tutorial
Play a complete Golf Solitaire card game made with HTML5 canvas, then copy the free source code and learn the deck, shuffle, rules and tap controls.
- Slot Machine and Casino Games in HTML5: Free Code (No Real Money)
A free HTML5 slot machine that uses play credits only: copy the source code and learn how reels, paylines, paytables, RTP and fair randomness work.
- Clicker and Idle Game in HTML5: Full Code and Tutorial
Play a complete HTML5 clicker and idle game, then copy the free code and learn how rising costs, passive income, big numbers and prestige work.
- Drag-and-Drop Game in HTML5: Code, Tutorial and Template
Play a drag-and-drop sorting game built on HTML5 canvas and Pointer Events, then copy the free code and learn how picking up, dropping and snap-back work.
- Dress-Up Game in HTML5: Full Code and Step-by-Step Tutorial
Play a dress-up game made with HTML5 canvas, then copy the free code and learn how clothing slots, colours, layering and outfit rating work.
- Endless Runner in HTML5 Canvas: Full Runner Game Code
Play a free endless runner made with HTML5 canvas, then copy the code and learn how jumping, ducking, obstacle spawning and rising speed work.
- Conway's Game of Life in HTML5 Canvas: Full Code and How It Works
Run Conway's Game of Life on an HTML5 canvas: draw cells, play, pause and step, try famous patterns, then copy the free code and see how it works.
- Match-3 Game in HTML5: Gem-Matching Code and Tutorial
Play a complete match-3 game made with HTML5 canvas, then copy the free code and learn how swaps, matches, gravity, refills and cascades work.
- Maze Game in HTML5 Canvas: Full Source Code and Tutorial
Play a random maze game made with HTML5 canvas, then copy the free source code and learn how maze generation, grid movement and the timer work.
- Memory Match Game in HTML5: Full Code and Tutorial
Play a memory match game built on HTML5 canvas, then copy the free MIT code and learn how the shuffle, card flips, pair checks and scoring work.
- HTML5 Platformer Game: Full Code and Side-Scrolling Tutorial
Play a Mario-style platformer made with HTML5 canvas, then copy the free code and learn tile collision, jumping, scrolling and enemies step by step.
- Pong Game in HTML5 Canvas: Full JavaScript Code and Tutorial
Play a Pong-style game built with HTML5 canvas, then copy the free JavaScript and learn how the paddles, ball physics, computer player and scoring work.
- Puzzle Games in HTML5: Sliding, Jigsaw and Sudoku Code
Play a free sliding puzzle made with HTML5 canvas, copy the code and learn how to create puzzle games, with notes on jigsaw and sudoku versions.
- Quiz and Trivia Game in HTML5: Code and Template
Play a quiz and trivia game built with HTML5 and real buttons, then copy the free code and learn how the questions, timer, 50:50 and scoring work.
- Car Racing Game in HTML5 Canvas: Full Code and Tutorial
Play a pseudo-3D car racing game made with HTML5 canvas, then copy the free code and learn how the road, curves, hills, traffic and lap timer work.
- Snake Game in HTML5 Canvas: Full Code and Tutorial
Play a complete Snake game made with HTML5 canvas and JavaScript, then copy the free code and learn how the loop, input, collisions and scoring work.
- Space Shooter in HTML5 Canvas: Full Code and Tutorial
Play a free space shooter made with HTML5 canvas and JavaScript, then learn how its waves, bullets, homing missiles and collisions work, step by step.
- Sports Games in HTML5: Basketball Code, Plus Soccer, Golf and Pool
Play a basketball shooting game made with HTML5 canvas, copy the free source code, and learn the physics behind soccer, golf and pool games too.
- Tetris-Style Game in HTML5: Full Code and Tutorial
Play a Tetris-style falling-blocks game made with HTML5 canvas, then copy the free code and learn rotation, wall kicks, line clears and lock delay.
- Tower Defense in HTML5: Full Game Code and Tutorial
Play a complete tower defense game made with HTML5 canvas, then copy the free code and learn paths, waves, targeting, three tower types and upgrades.
- Whack-a-Mole in HTML5: Full Game Code and Tutorial
Play a whack-a-mole game made with HTML5 canvas, then copy the free code and learn how the pop-up timing, rising speed, hit boxes and scoring work.
- Word Search and Word Games in HTML5: Code and Tutorial
Play a word search game built on HTML5 canvas, then copy the free source code and learn how words are placed, dragged, checked and turned into hangman.
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:
- HTML: a
<canvas>to draw on, plus a<title>and a viewport tag so it scales on phones. - CSS: a few lines that make the canvas fill the screen and stop the page from scrolling during play.
- 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.