Tile Merge 2048 Puzzle with 20 Levels, Stones & Daily Game
Tile Merge 2048 Puzzle · Games · Plain HTML, CSS & JS · Live preview
For supporters
Source Code
Want the source code?
Play the game for free. Become a WebDevPuneet supporter to unlock the complete HTML, CSS and JavaScript source code, the exports (HTML, React, Vue, Angular, Tailwind) and Fork.
Extend with AI
Take This Snippet Further With AI
The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.
What's included
Features
About this UI Snippet
Tile Merge 2048 — Sliding Animation, 20 Levels, Bigger Boards, Stones, Undo, Smash and a Daily Game

2048 is a sliding puzzle: every move slides all tiles as far as they can go, equal neighbours merge into one tile of double the value, and a new tile appears. This version keeps that simple rule and adds a game around it: tiles that actually slide, 20 levels with different goals and board sizes, stones that get in the way, undo and a smash tool, a Daily Game with the same tiles for everyone, and the classic endless mode. It is plain HTML, CSS and JavaScript with no libraries, images or audio files.
Move logic that handles any board
The board is an n by n grid whose cells are empty, a stone, or a tile with an id and a value. slide() handles all four directions with one function: lineOf() lists the cells of a row or column starting at the side the tiles move towards, and each line is processed from that side. Tiles are placed one after another, and a tile merges into the previous one only if their values are equal and the previous one has not merged yet in this move, which is the rule that stops 2, 2, 4 becoming 8. A stone splits a line into separate segments, so tiles stop against it and never merge across it. The same code runs a 3x3, 4x4 and 5x5 board.
Tiles that really slide
The old way to draw a 2048 board is to redraw every tile after each move, which makes tiles jump. Here every tile is a persistent element with an id, positioned with a CSS transform. A move only changes the transform of each element, so the browser slides it. The tile that is merged into another slides to the same cell and fades, then the survivor pops with the new value, a spark burst shows for big merges and a floating "+score" text appears (with a combo label when three or more pairs merge at once). A new tile pops in after the slide finishes.
Levels with real goals
The LEVELS array lists 20 levels in four tiers. Warm-up levels use the 4x4 board with targets from 64 to 512, including a score target with a move limit. Big boards use 5x5 with goals up to 2048. Stones adds one to three fixed blocks on seeded positions (never in a corner). Master has tiny 3x3 boards and a 4096 goal. A level is cleared the moment the goal is reached. The par number of moves is calculated from the target, because a tile of value T needs at least about T divided by 2.2 moves, as the average spawn is 2.2.
Undo, smash and stars
Each level gives three undos (a snapshot stack of the grid, the score and the move count) and one smash that removes any tile. Both are optional helpers that cost the unassisted star. Stars are one for clearing the level, one for finishing within the par number of moves and one for using neither undo nor smash. Clearing a level unlocks the next.
Daily game, classic mode and saving
The Daily Game draws its new tiles from a seeded random generator (mulberry32), so everyone who plays the same moves gets the same game, and it has no undo or smash. Reach 512, 1024 or 2048 for one, two or three stars, and a streak builds when you play it on consecutive days. Classic mode is the endless game with your best score. All progress is saved to localStorage inside try/catch, so the game also runs in a sandboxed iframe where storage is blocked.
Controls and feel
Arrow keys or WASD slide the tiles, U undoes, H starts the smash tool and R restarts. On a touch screen you swipe on the board, and a tap removes a tile when the smash tool is active. Sounds come from a Web Audio synth (merge pitch rises with the tile value), big tiles glow, and the whole game scales to short preview areas.
Step by step
How to Use
- 1Pick a level, Classic or the Daily GameThe menu shows 20 levels in four tiers with their goals. Level 1 is open at first, and clearing a level unlocks the next. Classic is the endless game, and the Daily Game uses the same tiles for everyone.
- 2Slide the tilesUse the arrow keys or WASD, or swipe on a touch screen. Every tile slides as far as it can in that direction, and two tiles with the same number merge into one with double the value. A new tile appears after every move.
- 3Reach the goalThe goal card shows what to do, for example reach a 256 tile, or score 2500 points in 160 moves, with a progress bar. The moment you reach it the level is cleared.
- 4Watch out for stonesOn the Stones levels the grey blocks never move. Tiles stop against them and cannot merge across them, so plan your lines carefully.
- 5Use undo and smash when you are stuckUndo (U) takes back your last move, three times per level. Smash (H) removes any one tile you click. Both help, but using either costs you the unassisted star.
- 6Earn stars and chase the dailyOne star for clearing the level, one for finishing within the par number of moves, one for using no undo or smash. In the Daily Game, reach 512, 1024 or 2048 for one, two or three stars and keep your streak going.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
slide() merges a tile into the previous one only if the previous one has not merged in the same move. The two 2s merge into a 4, which is marked as merged, so the next tile (a 4) cannot merge into it in the same move. The next move can then merge the two 4s into an 8. This single-merge rule is what makes 2048 playable.
A stone is a cell that never moves and never holds a tile. When a line is processed, each stone ends the current segment, and the tiles on either side of it are slid and merged separately. So tiles stop right next to a stone and cannot merge across it. Stones are placed with a seeded random generator, never in a corner.
One star for reaching the goal, one for doing it in no more than the par number of moves, one for not using undo or smash. For a tile goal, par is the target divided by 2.2 (the average value of a new tile) times 1.3, because the board has to receive at least that much value from new tiles. For a score goal, par is 85 percent of the move limit.
New tiles come from a mulberry32 generator seeded with the day number. Every spawn uses the next numbers of that sequence, so if two players make the same moves they get the same tiles. The daily game has no undo or smash, so the result depends only on your moves.
Add an object to the LEVELS array: n is the board size, kind is tile or score, target is the tile or score to reach, limit is the move limit for score levels and stones is the number of fixed blocks. The menu shows five levels per tier, so add levels in fives or edit TIERS. Changing BOARD_PX or GAP changes the size of the board and the spacing.
Yes. All localStorage access is wrapped in try/catch, so a blocked storage only means that progress and best score are not saved, and every sound call is wrapped too. Swipes on the board play the game, and a tap removes a tile when the smash tool is active. On narrow screens the side panel moves under the board.