How to Create a Phaser App: Step-by-Step
In this article
You create a Phaser app by starting a small local project folder, loading Phaser from a CDN or installing it with npm, and writing a single HTML page plus a JavaScript file that defines a scene. Phaser is a free, open-source HTML5 game framework that renders to Canvas or WebGL, so anything that runs a modern browser can run your game. The fastest working setup is a folder with an index.html that loads the Phaser script and a main.js that boots a scene, served through a local web server rather than opened as a file. The steps below cover that path, then how to move to the npm and bundler route once the basics work.
What You'll Need
- A computer running Windows, macOS or Linux with a modern browser (Chrome, Edge, Firefox or Safari).
- A plain text editor or code editor. Any editor works; one with JavaScript syntax highlighting makes life easier.
- Node.js and npm if you want the installed/bundled route. The CDN route needs neither.
- A local web server. Node's
npx serve, Python's built-inhttp.server, or the dev server that comes with a bundler all work. - Basic familiarity with HTML and JavaScript: variables, functions, and how a script tag loads a file.
Step-by-Step
- Create a project folder. Make an empty folder such as
my-phaser-gameand open it in your editor. Keep every file for the project inside it so relative paths stay simple. - Add an
index.htmlfile. This page holds the game container and loads your code. A minimal version includes a<div id="game"></div>element, a script tag pointing at the Phaser build, and a script tag pointing at your ownmain.js. Load Phaser first, your file second. - Load Phaser from the official CDN. Use the current Phaser 3 build hosted by the Phaser project or a reputable CDN, referenced by its full URL. Pin a specific version in the URL rather than a floating "latest" tag, so a future release cannot silently break your game.
- Create
main.jsand define a scene. A Phaser game is organised into scenes. Write a scene as a JavaScript object or class with acreate()method, and optionallypreload()for assets andupdate()for per-frame logic. Increate(), add something visible, such as a text label, so you can confirm the game booted. - Configure and start the game. Call
new Phaser.Game()with a config object. The config needs atype(usePhaser.AUTOto let Phaser pick WebGL or Canvas), awidthandheightin pixels, a parent element id matching the div in your HTML, a background colour, and asceneentry pointing at your scene. Phaser then creates the canvas inside that div. - Serve the folder over HTTP. Open a terminal in the project folder and start a local server. With Node installed,
npx serveis the quickest; with Python 3,python -m http.serverworks. Then open the address the server prints (usually a localhost URL with a port number) in your browser. - Confirm the game boots. You should see the canvas at the size you configured, with your placeholder text or shape. Open the browser's developer console; Phaser logs its version banner on startup, which confirms the library loaded.
- Add an asset and a sprite. Put an image in an
assetsfolder, load it inpreload()withthis.load.image(), and add it increate()withthis.add.image()orthis.physics.add.sprite(). Reload and check the image appears. This proves your asset paths resolve correctly. - Add input and motion. In
create(), set up keyboard input through the scene's input plugin, and inupdate()read the key states to change the sprite's position. This is the smallest complete loop: load, draw, respond to input. - Switch to npm when the prototype outgrows one file. Run
npm init -y, then install Phaser withnpm install phaser. Import Phaser at the top of your JavaScript entry file instead of using the CDN script tag, and use a bundler's dev server so modules resolve and the page reloads on save. From here, split scenes into separate files.
Common Mistakes
The most frequent failure is opening index.html directly from the file system. Browsers block many file-based requests, so images and JSON files fail to load and you get confusing console errors. Always use a local server.
Another common problem is script order: if your own file loads before Phaser, Phaser is undefined and nothing runs. A mismatched parent id between the config and the HTML div leaves you with a blank page and no error. Asset paths are case-sensitive on many servers, so Player.png and player.png are different files. Finally, mixing Phaser 2 tutorials with a Phaser 3 project produces errors like missing constructors, because the API changed substantially between major versions; check that any guide you follow targets the version you installed.
Tips
Keep the config in one place and grow it deliberately: scale settings, physics settings and scene lists all live there. Use Phaser.AUTO rather than forcing WebGL, so the game still runs on hardware with limited support. Name scenes clearly and register them in the config's scene array from the start, because adding a second scene later is easier when the pattern already exists. Watch the browser console while developing; Phaser reports missing assets and texture errors there rather than on the page. Pin your Phaser version in both the CDN URL and package.json, and commit a lockfile if you use npm, so the project behaves the same on another machine.
Troubleshooting
Blank page, no canvas: check the console first. A 404 on the Phaser script means the URL is wrong; a reference error means your script loaded before Phaser. Confirm the parent id in the config matches the div exactly.
Canvas appears but nothing is drawn: your scene may not be registered in the config, or create() may be throwing an error before it draws. Read the console output line by line.
Images missing: confirm the files exist at the exact path and casing, that they are loaded in preload() before use, and that you are serving over HTTP. Textures that fail to load show as green or missing boxes.
Game runs but input does nothing: make sure the canvas has focus, that keyboard input is set up in the scene, and that update() actually reads the key state each frame.
If that did not work: create a fresh minimal project with only the CDN script, an empty div and a scene that draws text. Once that runs, add your real code back piece by piece until it breaks, which isolates the faulty part quickly.
Frequently Asked Questions
Do I need Node.js to make a Phaser game?
No. The CDN route needs only a text editor and a local web server. Node.js becomes useful when you want npm packages, a bundler and a dev server with live reload.
Which Phaser version should I start with?
Start with the current Phaser 3 release and follow Phaser 3 documentation only. Tutorials written for Phaser 2 use a different API and will not work unchanged.
Can I use Phaser for a commercial game?
Phaser is open source under the MIT licence, which permits commercial use. Check the licence text shipped with the version you use if you need certainty for your situation.
Why does my game only work when served, not opened as a file?
Browsers restrict file-based requests for security. Loading images, audio and JSON from a local server avoids those restrictions and matches how the game will behave when hosted.
Does Phaser work on mobile browsers?
Yes. Phaser renders to Canvas or WebGL, which mobile browsers support. Configure the scale settings in the game config so the canvas fits different screen sizes, and test touch input rather than assuming keyboard controls.