Building a 2D Game with JavaScript Only
Beto, May 27, 2022 · 3,640 views
You can build a working 2D game with nothing but HTML, CSS, and vanilla JavaScript. No libraries, no frameworks, no build tools. If you're learning web dev, a small game teaches you more about how these three pieces fit together than another todo app ever will.
I build it from an empty folder in the video, so you can follow along and make it your own.
What's inside
- Set up a clean project with just , , and
- Center and stack elements with Flexbox
- Wire up a canvas as your game's drawing surface
- Move a character with keyboard arrow keys
- Debug real CSS mistakes as they happen (typos included)
Resources

CourseReact with TypeScript course
Once vanilla JS clicks, React is the next step. Build real projects with modern tooling.
Had a win? Get featured on Code with Beto.Share your story
Like this article? Get the rest of the library plus weekly React Native tips. Free.