๐ŸŽฎ All 30 games ยท $19

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.

  1. ๐Ÿ#1

    Snake

    EasyArcade150 lines

    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. โŒ#2

    Tic Tac Toe

    EasyBoard128 lines

    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. ๐ŸŸก#3

    Maze Muncher (Pac-Man Style)

    IntermediateArcade276 lines

    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. ๐Ÿค#4

    Flappy Bird

    EasyArcade126 lines

    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. ๐ŸŸช#5

    Tetris-Style Blocks

    IntermediatePuzzle173 lines

    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. ๐Ÿ”ข#6

    2048

    IntermediatePuzzle139 lines

    The 2048 number puzzle: slide the tiles, join equal numbers and reach 2048.

    โ–ถ Play demo & copy code
  7. ๐Ÿƒ#7

    Memory Card Game

    EasyPuzzle111 lines

    Flip two cards at a time and find all the pairs in as few moves as you can.

    โ–ถ Play demo & copy code
  8. ๐Ÿงฑ#8

    Breakout

    IntermediateArcade140 lines

    Breakout, the brick breaker classic: bounce the ball off your paddle and break every brick.

    โ–ถ Play demo & copy code
  9. ๐Ÿ“#9

    Pong

    EasyArcade121 lines

    Pong in portrait mode, made for phones and computers: your paddle at the bottom, the computer at the top.

    โ–ถ Play demo & copy code
  10. ๐Ÿฆ–#10

    Dino Runner

    EasyArcade132 lines

    An endless runner like the Chrome offline dinosaur game: jump over the cactus as the game gets faster.

    โ–ถ Play demo & copy code
  11. ๐Ÿš€#11

    Space Shooter

    IntermediateArcade138 lines

    A vertical space shooter: your ship fires on its own while you dodge and blast the falling aliens.

    โ–ถ Play demo & copy code
  12. ๐ŸŽ๏ธ#12

    Car Racing

    EasyArcade134 lines

    A top-down car racing game: change lanes to dodge the traffic as the road gets faster.

    โ–ถ Play demo & copy code
  13. ๐Ÿ”ฒ#13

    Sliding Puzzle

    EasyPuzzle147 lines

    The classic 15 puzzle: slide the numbered tiles into the empty space until they are in order.

    โ–ถ Play demo & copy code
  14. ๐Ÿน#14

    Whack-a-Mole

    BeginnerWord & quick109 lines

    Hit as many moles as you can in 30 seconds, but watch out for bombs.

    โ–ถ Play demo & copy code
  15. ๐Ÿ”ด#15

    Simon Says

    EasyPuzzle118 lines

    Watch the colors light up and repeat the pattern.

    โ–ถ Play demo & copy code
  16. ๐Ÿ’ฃ#16

    Minesweeper

    IntermediatePuzzle120 lines

    Classic Minesweeper with a safe first click: open the squares, read the numbers and flag every mine.

    โ–ถ Play demo & copy code
  17. ๐ŸŸก#17

    Connect Four

    IntermediateBoard134 lines

    Drop discs into the columns and get four in a row before your opponent.

    โ–ถ Play demo & copy code
  18. ๐Ÿ”ค#18

    Hangman

    BeginnerWord & quick121 lines

    Guess the hidden word one letter at a time before the drawing is finished.

    โ–ถ Play demo & copy code
  19. โœŠ#19

    Rock Paper Scissors

    BeginnerWord & quick101 lines

    Rock Paper Scissors against the computer with a shake animation before every reveal.

    โ–ถ Play demo & copy code
  20. ๐ŸŽฏ#20

    Number Guessing

    BeginnerWord & quick98 lines

    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. โŒจ๏ธ#21

    Typing Speed Test

    BeginnerWord & quick112 lines

    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

#GameTypeLevelCodeWhat you learn
1๐Ÿ SnakeArcadeEasy150 linesGrid movement and a setTimeout game loop
2โŒ Tic Tac ToeBoardEasy128 linesThe minimax algorithm (an unbeatable AI)
3๐ŸŸก Maze Muncher (Pac-Man Style)ArcadeIntermediate276 linesGrid movement, ghost AI targets and game states
4๐Ÿค Flappy BirdArcadeEasy126 linesGravity, velocity and requestAnimationFrame
5๐ŸŸช Tetris-Style BlocksPuzzleIntermediate173 linesMatrix rotation, collision checks and clearing lines
6๐Ÿ”ข 2048PuzzleIntermediate139 linesArray logic: sliding and merging rows
7๐Ÿƒ Memory Card GamePuzzleEasy111 linesFisherโ€“Yates shuffle and 3D card flips in CSS
8๐Ÿงฑ BreakoutArcadeIntermediate140 linesBall physics and circleโ€“rectangle collision
9๐Ÿ“ PongArcadeEasy121 linesA simple AI opponent and bounce angles
10๐Ÿฆ– Dino RunnerArcadeEasy132 linesJump physics and spawning obstacles
11๐Ÿš€ Space ShooterArcadeIntermediate138 linesBullets, spawning enemies and particle explosions
12๐ŸŽ๏ธ Car RacingArcadeEasy134 linesLane movement and a difficulty curve
13๐Ÿ”ฒ Sliding PuzzlePuzzleEasy147 linesGrid indexes and an always-solvable shuffle
14๐Ÿน Whack-a-MoleWord & quickBeginner109 linesTimers (setTimeout / setInterval) and DOM events
15๐Ÿ”ด Simon SaysPuzzleEasy118 linesasync / await sequences and the Web Audio API
16๐Ÿ’ฃ MinesweeperPuzzleIntermediate120 linesFlood fill and counting neighbours
17๐ŸŸก Connect FourBoardIntermediate134 linesWin detection in four directions and a simple AI
18๐Ÿ”ค HangmanWord & quickBeginner121 linesString checks and an SVG drawing
19โœŠ Rock Paper ScissorsWord & quickBeginner101 linesRandom choices and a rules lookup object
20๐ŸŽฏ Number GuessingWord & quickBeginner98 linesForms, input validation and binary search
21โŒจ๏ธ Typing Speed TestWord & quickBeginner112 linesInput 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

  1. Open a game and press โ–ถ Play to try it in the demo.
  2. Click ๐Ÿ“‹ Copy code (or โฌ‡ Download).
  3. Paste it into Notepad, TextEdit or VS Code and save it as game.html.
  4. 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.