Free ยท copy & paste ยท updated 2026-11-19
Free HTML Game Code: 21 Games to Copy and Paste
Here is free HTML game code for 21 complete games you can copy and paste: Snake, Tic Tac Toe, Flappy Bird, a Tetris-style game, 2048 and more. Every game is one .html file (HTML, CSS and JavaScript together) with no libraries, a live demo you can play right here, and touch controls for phones.
- 21games
- 1file each
- 0libraries
- ๐ฑphone ready
- โ๏ธworks offline
- $0free to use
-
๐#1
Snake
The classic Snake game in one HTML file: eat the apples, grow longer and don't hit the walls or yourself.
โถ Play demo & copy code -
โ#2
Tic Tac Toe
Tic Tac Toe with a smart computer opponent (minimax) and a 2-player mode for playing with a friend on the same screen.
โถ Play demo & copy code -
๐ก#3
Maze Muncher (Pac-Man Style)
A Pac-Man-style maze game in one HTML file: eat every dot, dodge four ghosts that each hunt you differently, and grab a power pellet to turn them blue and eat them for big points.
โถ Play demo & copy code -
๐ค#4
Flappy Bird
A Flappy Bird-style game drawn entirely with the canvas (no images): tap to flap through the gaps in the pipes.
โถ Play demo & copy code -
๐ช#5
Tetris-Style Blocks
A falling-blocks puzzle in the style of Tetris: 7 piece shapes, rotation with wall kicks, a ghost piece, next-piece preview, levels and on-screen buttons for phones.
โถ Play demo & copy code -
๐ข#6
2048
The 2048 number puzzle: slide the tiles, join equal numbers and reach 2048.
โถ Play demo & copy code -
๐#7
Memory Card Game
Flip two cards at a time and find all the pairs in as few moves as you can.
โถ Play demo & copy code -
๐งฑ#8
Breakout
Breakout, the brick breaker classic: bounce the ball off your paddle and break every brick.
โถ Play demo & copy code -
๐#9
Pong
Pong in portrait mode, made for phones and computers: your paddle at the bottom, the computer at the top.
โถ Play demo & copy code -
๐ฆ#10
Dino Runner
An endless runner like the Chrome offline dinosaur game: jump over the cactus as the game gets faster.
โถ Play demo & copy code -
๐#11
Space Shooter
A vertical space shooter: your ship fires on its own while you dodge and blast the falling aliens.
โถ Play demo & copy code -
๐๏ธ#12
Car Racing
A top-down car racing game: change lanes to dodge the traffic as the road gets faster.
โถ Play demo & copy code -
๐ฒ#13
Sliding Puzzle
The classic 15 puzzle: slide the numbered tiles into the empty space until they are in order.
โถ Play demo & copy code -
๐น#14
Whack-a-Mole
Hit as many moles as you can in 30 seconds, but watch out for bombs.
โถ Play demo & copy code -
๐ด#15
Simon Says
Watch the colors light up and repeat the pattern.
โถ Play demo & copy code -
๐ฃ#16
Minesweeper
Classic Minesweeper with a safe first click: open the squares, read the numbers and flag every mine.
โถ Play demo & copy code -
๐ก#17
Connect Four
Drop discs into the columns and get four in a row before your opponent.
โถ Play demo & copy code -
๐ค#18
Hangman
Guess the hidden word one letter at a time before the drawing is finished.
โถ Play demo & copy code -
โ#19
Rock Paper Scissors
Rock Paper Scissors against the computer with a shake animation before every reveal.
โถ Play demo & copy code -
๐ฏ#20
Number Guessing
The computer picks a number from 1 to 100 and you have 7 tries to find it, with higher/lower hints and a bar that shows where the number can still be.
โถ Play demo & copy code -
โจ๏ธ#21
Typing Speed Test
Type the words as fast as you can for 30 seconds and get your words per minute (WPM) and accuracy.
โถ Play demo & copy code
All 21 HTML games compared
| # | Game | Type | Level | Code | What you learn |
|---|---|---|---|---|---|
| 1 | ๐ Snake | Arcade | Easy | 150 lines | Grid movement and a setTimeout game loop |
| 2 | โ Tic Tac Toe | Board | Easy | 128 lines | The minimax algorithm (an unbeatable AI) |
| 3 | ๐ก Maze Muncher (Pac-Man Style) | Arcade | Intermediate | 276 lines | Grid movement, ghost AI targets and game states |
| 4 | ๐ค Flappy Bird | Arcade | Easy | 126 lines | Gravity, velocity and requestAnimationFrame |
| 5 | ๐ช Tetris-Style Blocks | Puzzle | Intermediate | 173 lines | Matrix rotation, collision checks and clearing lines |
| 6 | ๐ข 2048 | Puzzle | Intermediate | 139 lines | Array logic: sliding and merging rows |
| 7 | ๐ Memory Card Game | Puzzle | Easy | 111 lines | FisherโYates shuffle and 3D card flips in CSS |
| 8 | ๐งฑ Breakout | Arcade | Intermediate | 140 lines | Ball physics and circleโrectangle collision |
| 9 | ๐ Pong | Arcade | Easy | 121 lines | A simple AI opponent and bounce angles |
| 10 | ๐ฆ Dino Runner | Arcade | Easy | 132 lines | Jump physics and spawning obstacles |
| 11 | ๐ Space Shooter | Arcade | Intermediate | 138 lines | Bullets, spawning enemies and particle explosions |
| 12 | ๐๏ธ Car Racing | Arcade | Easy | 134 lines | Lane movement and a difficulty curve |
| 13 | ๐ฒ Sliding Puzzle | Puzzle | Easy | 147 lines | Grid indexes and an always-solvable shuffle |
| 14 | ๐น Whack-a-Mole | Word & quick | Beginner | 109 lines | Timers (setTimeout / setInterval) and DOM events |
| 15 | ๐ด Simon Says | Puzzle | Easy | 118 lines | async / await sequences and the Web Audio API |
| 16 | ๐ฃ Minesweeper | Puzzle | Intermediate | 120 lines | Flood fill and counting neighbours |
| 17 | ๐ก Connect Four | Board | Intermediate | 134 lines | Win detection in four directions and a simple AI |
| 18 | ๐ค Hangman | Word & quick | Beginner | 121 lines | String checks and an SVG drawing |
| 19 | โ Rock Paper Scissors | Word & quick | Beginner | 101 lines | Random choices and a rules lookup object |
| 20 | ๐ฏ Number Guessing | Word & quick | Beginner | 98 lines | Forms, input validation and binary search |
| 21 | โจ๏ธ Typing Speed Test | Word & quick | Beginner | 112 lines | Input events and the WPM formula |
Every game: HTML + CSS + JavaScript in one file ยท no external links or dependencies ยท responsive with touch controls ยท best score saved in the browser.
โญ All 21 games are also on GitHub: github.com/โฆ/html-games-code (MIT license). Clone the whole set or star it for later.
How to run any of these games
- Open a game and press โถ Play to try it in the demo.
- Click ๐ Copy code (or โฌ Download).
- Paste it into Notepad, TextEdit or VS Code and save it as
game.html. - Double-click the file. It opens in Chrome, Safari, Firefox or Edge and works offline.
Which game should you start with?
Beginner
Whack-a-Mole ยท Hangman ยท Rock Paper Scissors ยท Number Guessing ยท Typing Speed Test
Easy
Snake ยท Tic Tac Toe ยท Flappy Bird ยท Memory Card Game ยท Pong ยท Dino Runner ยท Car Racing ยท Sliding Puzzle ยท Simon Says
Intermediate
Maze Muncher (Pac-Man Style) ยท Tetris-Style Blocks ยท 2048 ยท Breakout ยท Space Shooter ยท Minesweeper ยท Connect Four
Beginner games use buttons and plain HTML elements. Easy games add a canvas and a game loop. Intermediate games add collision maths, grids and simple AI.
What makes these free games different
- Every game is hosted here and playable on this page; no links out to other sites
- One file, zero dependencies: nothing breaks when a CDN goes down
- Made for phones and computers: touch, swipe, mouse and keyboard
- Readable, commented code with every setting at the top of the script
- Each page explains how the code works, step by step
FAQ
What is HTML game code?
HTML game code is a complete browser game written in HTML, CSS and JavaScript. Save it as a .html file and it runs in any browser, offline, with nothing to install. Every game on this page is a single file like that.
Where can I find free HTML game code to copy and paste?
Right here: 21 games, each with a Copy code button, a download and a live demo. Popular ones are the Snake game, Tetris, Minesweeper and Tic Tac Toe.
Are these HTML games really free?
Yes. All 21 games are free to copy, change and use in personal, school and commercial projects, including your own website or app. A link back to HTML Games Code is welcome but not required.
How do I run an HTML game from this page?
Open a game, click Copy code (or Download), paste it into any text editor and save it as a .html file. Double-click the file and it opens in your browser. Nothing to install, and it works offline.
Do I need a server, a framework or a library?
No. Each game is a single file with its HTML, CSS and JavaScript together. There are no libraries, CDNs, images or sound files to download.
Which HTML game is easiest for beginners?
Start with Whack-a-Mole, Hangman, Rock Paper Scissors, Number Guessing, Typing Speed Test. They use plain HTML elements and events. Next try the Easy canvas games such as Snake and Flappy Bird, then the Intermediate ones like Tetris-style blocks and Minesweeper.
Do the games work on mobile phones?
Yes. Every game has touch controls (taps, swipes or on-screen buttons) and fits a phone screen, as well as keyboard and mouse controls on a computer.
Can I put these games on my own website?
Yes. Paste the code into its own .html page, or upload the file and show it inside an iframe on any page, including WordPress and Blogger.
Can I turn an HTML game into an Android app?
Yes. Any HTML game can be wrapped in an Android app (APK). For our premium games the HTML Games APK Builder does it with AdMob ads included; for these free files you can use a tool such as htmltoapk.com.
What is the difference between these and your premium games?
These 21 games are short, simple and made for learning. The premium games (all 30 for $19) are complete products with levels, shops, daily rewards, AdMob ads and a signed Android APK.