A 126-Card Kids Recognition Game Ships as One 2.3MB HTML File, No Build Step Required
I Used AI to Build My Child a Recognition Game: A 2.3MB Single-File HTML with 126 Cards and Three Game Modes, Playable on Phone or Tablet
Author: 墨林陌 Tags: 前端
First, here's the finished product: scan the QR code or open it and play. No login, no ads, no countdown:
https://4mhbm5naez8em.doubao.link/app/app_17j70csr606
It's called "卡片乐园" ("Card Playground"), for ages 3–6: 11 categories, 126 recognition cards, and three game modes (认一认 / 连一连 / 翻翻乐). The entire game is one HTML file; the image assets are in a nearby assets/ directory. There is no build step, no npm, no framework.
This article is not about "how powerful AI is"; it covers two things: how the requirements were wrung out through rounds of questions, and which implementation details are worth copying.
1. Requirements are not thought up, they are wrung out
The first sentence I gave was only four characters: "益智游戏" ("educational game").
I was then asked three things: who it's for, what form it takes, and what skill it should train. Once the answers were set, the whole project boundary became clear:
- Ages 3–6, near-zero literacy, so the less interface text the better; communicate through images and sound;
- Need "object recognition + memory", so there is matching and card recognition;
- What parents explicitly don't want: countdowns, leaderboards, points, combo effects.
These three decisions drove every later trade-off. "No time limit" is not just copy; it means the progress bar only shows "found 3 / 6 pairs" and never turns red because you are slow.
First version only had one game: flip and match, with 3D flipping cards, star progress, Web Audio-synthesized sound effects, and confetti dropping on winning. The assets were AI-generated cartoon illustrations, uniformly resized to 512px JPEGs.
Second version added categories: vegetables, fruits, animals, vehicles, and mixed.
Third version was the biggest structural change: the user gave a clear hierarchy:
认一认: category → tap type → cards appear → tap card to read info and hear introduction 连一连: category, tap matching items to connect 翻翻乐: memory matching
The page went from "one board" to five screens: home, choose category → choose mode → corresponding mode (plus a card-detail popup and a completion popup).
Fourth version expanded: categories from 5 to 9, each had 8 cards becoming 10, cards from 32 to 80. The 48 new illustrations were generated in four batches, downloaded in batches, and resized to 512px / JPEG q85 using Windows' built-in System.Drawing (PIL was not installed on this machine; the ready-made solution was simpler).
Fifth version published it as an accessible link (this step was more important than I expected, as the pitfall section will explain).
Sixth version made experience optimizations: notch safe area, remember the last selected category and difficulty, a line that "grows" out in the matching game, and on successful match a bounce plus a green checkmark.
Seventh version added three types of "concept cards": recognizing numbers (1–10), recognizing letters (A–Z), and colors / shapes / size. This version changed the asset format; the reason is in section 3 below.
Eighth version added visit records: record every local open, every game round (including category and card count), and every completion.
Eight rounds, and each change was to the same HTML file, with the same filename. On the final version with 126 cards, the size arithmetic is simple: the HTML itself is 106KB, the 80 compressed illustrations are 2.2MB, total 2.3MB, and after one open everything is cached locally.
The 126 cards split up as:
| Category | Cards | Asset format |
|---|---|---|
| Small animals / fruits / vegetables / vehicles / food / clothes / toys / nature | 10 each, 80 total | AI illustrations (JPEG) |
| Numbers | 10 (1–10) | Inline SVG |
| Letters | 26 (A–Z) | Inline SVG |
| Colors and shapes | 10 (4 colors + 4 shapes + big/small) | Inline SVG |
2. Why "one HTML file" instead of "a project"
For a young child, the delivery chain is itself part of the experience. I wanted three things:
- Double-click to open, without installing Node or running
npm install; - Send a link, which also opens on a grandparent's phone;
- Offline capable, so it does not white-screen when the network drops.
So: CSS is inlined in a <style> block, JS is inlined in a <script> block, state is a plain object plus several re-render functions, no framework, no type="module". The whole thing has only one constraint to obey: asset references must be statically scannable by the publishing chain — described separately below.
3. Why concept cards abandoned AI illustrations for inline SVG
For numbers, letters, and shapes, I initially planned to keep generating illustrations. Thinking about it, it was not a good fit:
- The number 7 drawn as "seven stars next to it" could be rendered as six or eight — the error rate is uncontrollable;
- There are 26 letters; uppercase and lowercase would each need an image, so 52 images total, a bad deal for both size and generation rounds;
- A color card made as an illustration shows the child "a red apple", and what the child remembers is the apple, not the color red.
Switching to vector drawing solved all of these at once:
- Numbers 1–10: a large digit plus dots whose count exactly matches the number; the dot count is computed in code and cannot be wrong;
- Letters: uppercase letter above lowercase letter, completely legible;
- Colors: a single solid color block with nothing to distract;
- Shapes: circle / square / triangle / star, solid fill, clean edges, no interference from illustration shadows or textures;
- Size: draw one large circle and one small circle in the same frame; the target is solid and the reference is pale — the comparison is obvious at a glance.
The key point is that the card retrieval logic never changed; this only added a dispatch function:
function faceNode(key){
var item = itemByKey(key);
if (item && item.art) return artNode(item.art); // concept cards: draw SVG on the spot
return faceImage(key); // physical cards: clone <img> from hidden gallery
}
There are five places in the site that get a card's front face (homepage preview, recognition grid, recognition detail, connect thumbnails, and flip-card face), and they were all switched to call faceNode. 46 vector cards, added bytes: 0.
4. Four implementation details worth copying
1. Hidden gallery + clone: to make the publishing chain see the images
When you publish a single-file HTML, the platform statically scans only <img src>, <link href>, and CSS url(). If image paths are written in a JS array, or on a data-src attribute, after publishing the images all break.
So physical cards do not "build paths in JS"; all images are written once into a display:none gallery:
<div id="faceLib" style="display:none" aria-hidden="true">
<img src="assets/bear.jpg" alt="bear" data-key="bear">
<img src="assets/apple.jpg" alt="apple" data-key="apple">
<!-- ... 80 images total -->
</div>
At runtime, clone by data-key:
function faceImage(key){
var tpl = el.faceLib.querySelector('[data-key="' + key + '"]');
var img = tpl.cloneNode(true);
img.removeAttribute("data-key");
img.alt = "";
return img;
}
The benefits: image paths appear only in src attributes (the publisher can scan them), a card's front is always just the current image, and flipping a card triggers no new request — the 80 images in the gallery enter the cache on first load and everything after is a local hit. The cost is that the first screen pulls the full image set, so each image is kept to 512px / JPEG q85, 80 images totaling 2.2MB. The gallery images also get decoding="async" and draggable="false" uniformly, to avoid drag events and main-thread decoding jank on a phone.
2. Connect-game lines: SVG cubic Bézier + dash grow animation
The connecting lines are not drawn with Canvas; a <path> is inserted into a <svg> that overlays the playing field. Each pair gets one cubic Bézier:
var path = document.createElementNS(SVG_NS, "path");
path.setAttribute("d", "M" + x1 + " " + y1 + " C" + (x1 + (x2 - x1) * 0.45) + " " + y1 +
", " + (x2 - (x2 - x1) * 0.45) + " " + y2 + ", " + x2 + " " + y2);
path.setAttribute("stroke", pair.color);
path.setAttribute("stroke-width", "4");
Then the line is animated to "grow from left to right": first measure the path length, use stroke-dasharray to cut the entire line away, then animate stroke-dashoffset back to zero:
var len = path.getTotalLength();
path.style.strokeDasharray = len + " " + len;
if (fresh && !reduceMotion) {
path.style.strokeDashoffset = String(len);
// transition to 0 on the next frame, along with a CSS transition, gives the "drawn-on" effect
}
The fresh marker is only set on the line that was just created; on redraw, existing lines do not replay the animation — otherwise every tap would make all lines on the board twitch together.
3. The actual dealt pair count must be written back into state
This one closes a hole. Difficulty tiers are 4 / 6 / 8 / 10 pairs, but any category can have fewer cards than that (currently it is 10, 26, and 10, which is enough; later small categories may not be). The card selection already had a fallback:
var picks = shuffle(pool).slice(0, Math.min(pairs, pool.length));
state.pairs = picks.length; // the number of pairs actually dealt
If the progress bar, stars, and completion copy still read the pair count from the difficulty table, you get a dead end like "found 8 / 10 pairs" that can never be reached. So every display uses state.pairs, with no exceptions.
4. Four hard metrics for toddler interaction
- Hit areas ≥ 44px: category buttons all have
min-height:44px; children's finger precision is not the thing to blame; - No countdown: progress says "found X pairs", not "X seconds left";
- Feedback must be immediate: match success sound + a card bounce + green check in the top right, all three happen at the same time;
- Respect
prefers-reduced-motion: on a hit, all growth and bounce animations jump straight to their final state, and no confetti is thrown.
Sound effects are synthesized on the fly with Web Audio (OscillatorNode; flip 620Hz, match 660→880→1120, win 523→659→784→1046). No audio files are loaded, which keeps the package tiny. The conventions are followed: muted by default, requires one user tap (resume()) before it makes sound, a switch in the top right (role="switch"), volume 0.32, and the switch state is stored in localStorage. iOS's side mute switch silences the synthesized sound; that is covered by a small gray text hint, not a popup.
5. Pitfalls encountered (Windows + publishing chain)
| Pit | Symptom | Fix |
|---|---|---|
Chinese path in a .ps1 script |
Chinese characters decoded as GBK gibberish; New-Item complains "access denied" |
Keep the script text pure ASCII and derive the path from $PSScriptRoot |
| Image paths written in JS | Works fine locally, all images broken after publishing | Paths appear only in <img src> and CSS url() |
| Limit on images generated in one call | Requesting 48 at once throws an error | Generate in batches (10 + 10 + 10 + 8), then bulk download and compress |
Edit's old_string not unique |
Reports Found 2 matches, cannot apply edit |
Include surrounding context lines so the match becomes unique |
| Key collision | New shape card key collided with the "star" in nature | Prefix new cards (shapeStar / colorRed / sizeBig) |
| Slip under strict mode | One extra undeclared assignment kills the whole script with ReferenceError |
"use strict" throws this kind of mistake immediately; do not turn it off |
The publishing step itself was actually easy: single-file deployment automatically crawls the assets/ folder in the same directory for dependencies, so the 80 relative-path images did not need to be uploaded one by one:
lark-cli apps +deploy --file-path ./memory-pairs.html --app-id app_17j70csr606
In the response, check ok (not the exit code), then poll until status=finished and take online_url. After that, each iteration reuses the same app_id, so the link on phones never changes — which matters for "send it to family".
6. Access records: why local-only
The last added feature was visit records: every open, every game round (with category and card count), and every completion writes a line; at the bottom of the home page, tapping "access records" shows "open count / started plays / most recent", capped at 60 entries, with one-click clearing.
The implementation is an array in localStorage:
function addLog(kind, text){
var list = readLog();
list.push({t:Date.now(), kind:kind, text:text});
if (list.length > LOG_MAX) list = list.slice(list.length - LOG_MAX);
writeLog(list);
}
The write is wrapped in try/catch — in private mode localStorage throws directly, and that should not crash the whole game.
Boundary stated clearly: this is a local record; switching devices means you cannot see it. To get a real count of "how many people opened this link", a pure static single file cannot do it; you would need a backend statistics endpoint. That feature is left for later, once there is a server.
7. What you can play now
https://4mhbm5naez8em.doubao.link/app/app_17j70csr606
- 11 categories with 126 cards (plus a "mixed" entrance that puts all 126 into one pool): 小动物 / 水果 / 蔬菜 / 交通工具 / 食物 / 衣服 / 玩具 / 大自然 / 数字 / 字母 / 颜色形状
- Three play modes: 认一认 (tap cards to hear an explanation; supports keyboard ←/→ page turns), 连一连 (tap one card on the left and one on the right to connect them), 翻翻乐 (memory flip with 4 / 6 / 8 / 10 pairs)
- On phones, the notch and bottom gesture bar get automatic whitespace; category and difficulty remember the last choice
- Speech support via
speechSynthesis(zh-CN), with an automatic notice when unsupported
Next up: finer pinyin / English pronunciation details, more concept cards (time, opposites), and a learning footprint parents can view.
If you are also building a small tool for your kids, comments are welcome — especially about "how to place images so the publishing chain does not eat them". That is a lesson I paid tuition for.
Tech stack: Native HTML/CSS/JS (single file) · Web Audio synthesized sound · inline SVG · localStorage · SpeechSynthesis
Top 3 from juejin.cn, machine-translated. The original thread is authoritative.
Removing the countdown is crucial. Adding a countdown to a game for 3–4 year olds just creates anxiety; their hands aren't steady yet, and being rushed makes them cry. This detail shows real understanding of parenting, it's touching.
Very cleverly done. A single-file HTML is super convenient for parents—just save it and it works. For inspiration on such small tools, I usually browse AI tool directories like ai345, which sort by scenario for quick discovery and update frequently with new tools.
The greatest simplicity—click to play. It's clear a lot of thought went into this.