Slide How to Make 2048 (Browser Merge Grid 2026)

By Arron R.9 min read
How to make 2048 in 2026: keep a 4×4 integer grid, slide and merge equal tiles on arrow or swipe input, spawn a 2 or 4 on every valid move, and detect win at 20

Gabriele Cirulli shipped 2048 on 9 March 2014 as a free MIT-licensed browser puzzle built over a single weekend (verified against en.wikipedia.org/wiki/2048_(video_game) on 2026-08-19). The game drew more than four million visitors in its first week because the mechanic is tiny on paper and brutal in practice: slide numbered tiles on a 4×4 grid, merge equal neighbors, chase the 2048 tile before the board locks. Almost every weekend coder who searches how to make 2048 gets the CSS grid rendering fine, then stalls on the one-merge-per-line rule or the spawn-after-valid-move timing. The 2026 pipeline is different: a coding agent scaffolds the slide-and-merge kernel in one prompt, touch swipes reuse the same move function as arrow keys, and the whole game ships in an afternoon. In a browser, that means WizardGenie for the grid logic, SFX Gen for slide and merge chimes, and Music Gen for a calm ambient bed. This guide is the honest end-to-end for how to make 2048 in 2026.

How to make 2048 browser pipeline: 4x4 merge grid, swipe handlers, spawn logic, and score HUD with WizardGenie and Sorceress audio tools
The 2026 how to make 2048 browser recipe: model the 4×4 integer grid, slide and merge on arrow or swipe input, spawn a 2 or 4 after every valid move, and layer slide, merge, and game-over audio from SFX Gen.

What “how to make 2048” actually means in 2026

The query hides two different requests. Some searchers want a faithful tribute to Cirulli’s original: flat tan and gold tiles, the score and best-score HUD in the upper-right, the soft glow on high-value tiles, and the exact 90/10 spawn split between 2 and 4. Some searchers want a themed reskin — neon cyberpunk numbers, emoji tiles, a 5×5 hard mode, or a daily seed leaderboard. This guide targets the mechanic first because that is what the search phrase is really about. The original art is a specific visual identity; the merge-grid pattern is a game-design pattern you can reskin freely as long as you credit the MIT-licensed reference implementation if you fork Cirulli’s repo directly.

A quick naming note before the technical section. “2048” as a brand name refers to Cirulli’s published game and its official ports. You cannot ship a store listing called “2048” with identical art and claim it as your own product. The core mechanic — a square grid, tiles that slide until blocked, merges of equal values once per move, random spawns after valid moves, and a win condition at a target power-of-two — is a design pattern. Thousands of browser clones since March 2014 built on the same rules under different names (Merge Grid, Tile Slide, Power Two). Pick a distinct title, draw your own tile colors, write your own code, and you are on the same footing as every other weekend tutorial project.

The 2048 game loop in one minute (swipe slide merge spawn)

Five steps, in strict order, once per player input. First, read the direction (up, down, left, right) from an arrow key or a touch swipe whose dominant axis exceeds a small threshold. Second, slide every row or column in that direction so non-zero values compress toward the wall, preserving order. Third, merge adjacent equal values once per line: when two neighbors match and neither has merged this turn, replace them with double the value, add that value to the score, and mark the merged cell so it cannot merge again in the same move. Fourth, if the grid changed compared to the pre-move copy, spawn a new tile: pick a random empty cell and write 2 with ninety-percent probability or 4 with ten-percent probability (the ratio from the original 2048, verified 2026-08-19 on Wikipedia). Fifth, check termination: if any cell holds 2048 and you have not yet shown the win banner, offer continue or stop; if no empty cells remain and no adjacent equal pair exists in any direction, show game over.

That is the entire game. Everything else — undo stacks, best-score persistence in localStorage, animated tile slides, haptic feedback on mobile, dark mode, leaderboards — is polish on top of these five steps. If the loop is correct, the browser build feels like the 2014 original even on a mid-range phone. Resist animated tweens on the first pass; ship the pure discrete grid update, then add CSS transitions in a second pass once merge correctness is proven with unit tests.

2048 merge grid state machine: input direction, slide tiles, merge equals once per line, spawn 2 or 4, check win or game over
The five-step how to make 2048 loop: one direction in, slide and merge each affected line exactly once, spawn only if the board changed, then evaluate win and loss.

Pick your engine for how to make 2048: React, vanilla DOM, or Phaser 4

Three solid browser targets in 2026. Plain DOM plus a 4×4 integer array is the honest default. Sixteen <div> cells in a CSS grid, background colors keyed off Math.log2(value), and one keydown listener for arrows. The merge kernel is roughly eighty lines; the render pass maps array values to CSS classes. Touch swipes attach with touchstart and touchend handlers documented on MDN Touch events. Using divs instead of canvas keeps the DOM accessible and makes hot reload trivial.

React fits if the game lives inside a larger React app or you want component state to drive re-renders automatically. Store grid as nested arrays in useState, call move(direction) inside the key handler, and let React diff the tile list. The algorithm is identical to vanilla JS; you pay the React bundle cost for ecosystem convenience, not because 2048 requires it.

Phaser 4 is the pick if you plan animated tile tweens, particle bursts on merges, multiple board sizes, or a theme system that swaps sprite sheets. Phaser bundles scenes, tweens, and input in one package. For a first clone, plain DOM is faster to debug because you can console.log the grid after every move without fighting a scene graph.

WizardGenie scaffolds whichever stack you name. It runs as a desktop app with native filesystem access (Early Access tier and above) and as a no-install web build at the same URL. Describe the five-step loop in one paragraph and any model in the Sorceress coding lineup returns a working prototype. For cheap iteration, pair a frontier planner with a budget executor and let the executor type the merge functions while the planner sanity-checks edge cases like triple-merge prevention.

Step 1 — model the 4×4 grid, implement swipe direction handlers, and slide-and-merge logic

Start with let grid = Array.from({ length: 4 }, () => Array(4).fill(0)). Call an init() function that places two starting tiles using the same spawn helper you will reuse after every move. Build move(direction) by deep-copying the grid, transforming each affected line with a slideMerge(line) helper, and comparing the result to the copy. If equal, return false and do not spawn. If different, commit the new grid, spawn, and re-render.

The subtle part is slideMerge. For a left move on one row, filter zeros, walk the compressed array, and when arr[i] === arr[i+1] and neither slot is marked merged, write arr[i] * 2, skip the next index, and set a merged flag on the result cell. Push the merged row back into four cells, padding with zeros on the right. For right, up, and down, rotate or reverse the line before calling the same helper so you never maintain four separate merge implementations. Unit-test these cases before touching CSS: [2,2,0,0] becomes [4,0,0,0]; [2,2,2,0] becomes [4,2,0,0] not [8,0,0,0]; [4,4,4,4] becomes [8,8,0,0] on a left move.

Wire keyboard input with window.addEventListener('keydown', …) and map ArrowUp, ArrowDown, ArrowLeft, ArrowRight to directions. Prevent default on those keys so the page does not scroll. Add touch handling: record touchstart coordinates, on touchend compute dx and dy, ignore swipes shorter than thirty pixels, and call the same move() with the dominant axis. Play the build after this step; every arrow should shift tiles, merges should double values once, and a new 2 or 4 should appear only when something actually moved.

Step 2 — wire tile spawn, win/lose detection, and score tracking in WizardGenie

Open WizardGenie with your working grid file and ask for the spawn and termination layer: “After every successful move, collect all coordinates where grid[row][col] === 0, pick one uniformly at random, and assign 2 with probability 0.9 else 4. Track score by adding the value of every new merge tile. If any cell equals 2048 and winShown is false, set winShown and show a Continue / New Game overlay without blocking further moves. After each spawn, if there are no empty cells and move() returns false for all four directions, show Game Over with final score and a New Game button that resets grid, score, and winShown.”

Ask for persistence in the same session: “Store bestScore in localStorage on every score increase and display it beside the current score in the HUD.” That single line makes the clone feel finished. Optional polish paragraphs cover undo (keep a stack of grid snapshots before each move, cap depth at ten), animated slides (CSS transform with transition duration 120ms), and a restart key bound to R.

Tuning passes follow the same vibe-coding rhythm as every other browser classic in this series. If diagonals accidentally trigger on touch devices, raise the swipe ratio threshold. If the game accepts input during an animation, add an isAnimating guard. If merges feel too easy, log ten random games and confirm average game length matches expectations before you ship.

2048 browser game asset stack: optional AI tile skin, SFX Gen slide merge sounds, Music Gen ambient loop, under 56 Sorceress credits
2048 needs almost no art: CSS color steps handle every tile value. Budget a few SFX Gen clips and one Music Gen loop; an optional AI Image Gen skin is pure polish.

Step 3 — SFX Gen slide and merge chimes, Music Gen ambient bed

2048 is quiet by design, but three short clips add enormous feel. Open SFX Gen, which bills at 1 credit per second (verified 2026-08-19 in src/app/sfx-gen/page.tsx as SEED_AUDIO_CREDITS_PER_SECOND = 1). Prompt a soft slide whoosh at 0.2 seconds for every valid move, a brighter merge ping at 0.15 seconds when two tiles combine, and a muted thud at 0.4 seconds on game over. Three credits total if each clip rounds to one second of billing.

Open Music Gen for a seamless ambient pad. Music Gen costs 10 credits per generation (verified 2026-08-19 in src/app/music-gen/page.tsx line 28). Prompt “calm minimalist synth pad, 30 seconds seamless loop, 60 BPM, puzzle-game background, no percussion” and loop it quietly under the game. Add a mute toggle; many players prefer silence while they plan merges.

Custom tile skins are optional. The classic look is CSS background colors keyed off exponent: tan for low tiles, gold for 128+, glow above 512. If you want illustrated tiles, generate one 4×4 sprite sheet in AI Image Gen at Nano Banana Pro for 18 credits per pass (src/lib/models.ts line 303). Skip art entirely on v1; ship the CSS version first.

What a how to make 2048 project costs on Sorceress in 2026

Concrete budget from empty repo to playable zip, verified 2026-08-19 against local Sorceress source:

  • Grid and tiles: zero credits. CSS grid-template-columns: repeat(4, 1fr) and exponent-based background colors render every value through 131072 without a single image.
  • Audio pack (SFX Gen): three clips at roughly 1 credit each, about 0.03 USD.
  • Ambient loop (Music Gen): 10 credits per generation, two tries typical, about 0.20 USD.
  • Optional tile skin (AI Image Gen): 0 to 36 credits depending on whether you generate one or two sheet variations, about 0.00 to 0.36 USD.
  • WizardGenie coding: model API cost only; a DeepSeek V4 Pro or Kimi K2.5 executor session for this scope typically stays under 0.40 USD.
  • Total: about 23 to 59 credits, or 0.23 to 0.59 USD in Sorceress credits, plus under 0.40 USD in model time. Well under two dollars end-to-end.

When the loop feels tight, export the folder, host on GitHub Pages or itch.io, and link back to the Sorceress tools guide if you used the audio stack. The merge-grid mechanic is a rite of passage for browser puzzle devs; Cirulli proved it fits in a weekend, and WizardGenie keeps that timeline honest in 2026.

Frequently Asked Questions

Do I need React to make a browser 2048 game?

No. A first 2048 clone runs fine in plain JavaScript with a CSS grid of sixteen divs and one keydown listener for arrow keys. React helps if you already host the game inside a larger app or want hot reload during a jam, but the merge algorithm is the same either way: copy the grid, slide each row or column, merge adjacent equal values once per move, compare the copy to detect whether anything changed, then spawn. WizardGenie scaffolds whichever stack you name in the prompt.

How does the 2048 spawn rule work?

After every move that changed the board, pick a random empty cell and place either a 2 or a 4. Gabriele Cirulli’s original 2048 (released 9 March 2014, verified 2026-08-19 on en.wikipedia.org/wiki/2048_(video_game)) spawns 2 ninety percent of the time and 4 ten percent of the time. Build an array of every coordinate where grid[row][col] === 0, pick one index with Math.floor(Math.random() * empties.length), and write the chosen value. If no empty cells remain and no merge is possible, trigger game over.

Why do my tiles merge twice in one swipe?

Each row or column may merge at most once per move. When sliding left, scan from the inner edge toward the wall: push non-zero tiles together, and when two neighbors match and neither has already merged this turn, combine them into double the value and mark the result as merged. Reset the merged flags before processing the next swipe. If you recurse or loop until no merges remain inside a single swipe, you will overshoot the official rules and the board will feel too easy.

Should a 2048 clone support touch swipes?

Yes for any public browser build in 2026. Desktop players expect arrow keys; phone players expect swipe gestures. Track touchstart and touchend coordinates, compare deltaX and deltaY, and map the dominant axis to up, down, left, or right. Call the same move() function the keyboard handler uses so logic stays in one place. MDN documents the Touch events API for the pointer math; keep a minimum swipe threshold of about thirty pixels so accidental taps do not shift the grid.

How much does it cost to build 2048 on Sorceress?

A minimal browser 2048 with CSS tiles needs almost no art credits. Budget roughly 6 credits (0.06 USD) for three SFX Gen clips at 1 credit per second (verified 2026-08-19 in src/app/sfx-gen/page.tsx), 20 to 30 credits (0.20 to 0.30 USD) for one or two Music Gen ambient loops at 10 credits per generation (src/app/music-gen/page.tsx line 28), and optionally 18 credits (0.18 USD) per custom tile skin pass in AI Image Gen at Nano Banana Pro 18 credits (src/lib/models.ts). Total under 56 credits or about 0.56 USD in Sorceress credits plus under 0.40 USD in model API time for WizardGenie scaffolding.

Sources

  1. 2048 (video game) — Wikipedia
  2. MDN — Touch events (swipe input on mobile browsers)
  3. MDN — KeyboardEvent (arrow-key input)
  4. Phaser 4 API Documentation
Written by Arron R.·2,004 words·9 min read

Related posts