About this tool
A free maze generator that runs entirely in your browser. Choose a grid size, pick an algorithm, and click Generate. The maze renders as crisp SVG that you can print on Letter paper, download as a file, or solve right on the screen with the solution toggle. Every maze is a "perfect" maze — exactly one path connects the start (top-left) to the finish (bottom-right), with no loops and no isolated rooms.
Built for teachers needing a sub-day filler, parents passing a long car ride, kids who just like mazes, and anyone curious about how a computer draws them. Nothing is sent anywhere; there is no signup; the whole tool is a single page of HTML, CSS, and a small JavaScript file you can view from your browser.
Prefer to solve on screen? Hit Play after generating. A green marker drops on the start, arrow keys (or WASD, or the on-screen direction buttons on a phone) move you one cell at a time, walls block movement, and a timer starts on your first move and stops the moment you reach the exit. The tool remembers your best time per maze size in your browser, so generating a second 25×25 lets you race the same size against yourself.
How the maze is generated
Every maze starts as a grid of cells with all four walls intact. Connecting cells means knocking down the walls between them. The interesting question is which walls to knock down — and that's what an algorithm decides.
Recursive backtracker
Pick a starting cell, mark it visited, and put it on a stack. Then repeat: look at the current cell's neighbors that haven't been visited yet. If there is at least one, pick one at random, knock down the wall between them, move there, and add it to the stack. If there are no unvisited neighbors, pop the stack and try again from the previous cell. Stop when the stack is empty.
The behavior is exactly what the name suggests — the algorithm goes as deep as it can before backtracking. That produces long winding passages with relatively few branches. If you imagine yourself walking through, you'll feel like you're being led somewhere for a long stretch before being forced to commit to a turn.
Prim's algorithm
Maintain a list of frontier walls — walls between cells that are already in the maze and cells that aren't. Pick one frontier wall at random, knock it down, and add the new cell to the maze. Add that cell's outgoing walls to the frontier list. Repeat until every cell is in the maze.
The randomness happens across the whole growing edge of the maze instead of always extending from the last placed cell. That produces a different texture: shorter dead ends, more frequent branching, less of the long-corridor feel. Same level of difficulty, different signature.
Why both produce solvable mazes
Both algorithms build the maze one wall at a time and never remove a wall twice. That guarantees the resulting maze is a spanning tree of the grid: every cell is reachable from every other cell, and there is exactly one path between any two cells. So the answer to "is there a path from start to finish?" is always yes, and the path is unique.
The solution overlay finds that path with a breadth-first search. BFS starts at the top-left, fans out through every cell it can reach, and stops when it lands on the bottom-right. In a perfect maze the resulting path is the path — there is no other.
Classroom ideas
The "right" size depends mostly on who's solving it. Rough guide:
- K–2 (Small, 15×15). Finishable in two or three minutes. Good as a wait-time activity or transition.
- Grades 3–5 (Medium, 25×25). A real puzzle without being a slog. Most kids will finish in five to ten minutes.
- Grades 6–8 (Large, 35×35). Long enough that finishing feels earned. Pair it with a stopwatch and compete.
- High school and up (Custom, up to 60×60). Print a 50×50 or 60×60 maze, hand it out as a "if you finish early" task, and watch students stay glued to it.
Sub-day filler. Print one maze per algorithm at the same size, plus a third copy with the solution overlay on. Students try both, then look at the third to compare which one their actual route matched. Stealth lesson: two different "random" processes don't produce equally hard puzzles.
Brain break. Print a class set of medium mazes at the start of the year and keep them in a folder. When the room needs a five-minute reset, hand them out. Quiet, self-paced, finishes naturally.
Estimation warm-up. Before students start, have them estimate the number of cells on the optimal path. After they finish, count it together. Older students can predict how that count grows with grid size and check against the maze you generate next.
Coding-club starter. Show students the recursive-backtracker explainer above and ask them to implement it themselves. The algorithm is small enough that a high schooler can get a working version in an afternoon, and the result is visually rewarding in a way most introductory programming exercises aren't.
For more printable activities, see the Word Search Generator — same printable-plus-playable pattern — or browse all teacher tools.
Frequently asked questions
What size maze should I print?
Match the size to who's solving it. Small (15×15) is right for K–2 — finishable in a few minutes. Medium (25×25) is a fair puzzle for grades 3–5. Large (35×35) suits grades 6–8 and adults who want a real challenge. For older students or maze enthusiasts, use the Custom option to go up to 60×60 — that's the biggest size that still prints legibly on a single Letter-size page.
What's the difference between the algorithms?
Recursive backtracker produces long, winding passages — the algorithm keeps going until it paints itself into a corner, then backs up. The result feels like one big snaking corridor with side branches. Prim's algorithm picks walls to remove at random across the whole maze instead of extending from the last cell, which produces shorter dead ends and more branching. Both make solvable mazes; they just feel different to solve. Try generating the same size with each algorithm to see the difference.
Are these mazes always solvable?
Yes. Every maze is a perfect maze — there is exactly one path between any two cells, no isolated rooms, no loops. The start (top-left) and finish (bottom-right) are always connected. Turn on Show solution to see the unique path overlaid on the maze.
Can I use these for a classroom activity?
Yes — that's one of the reasons it exists. Generate one maze per algorithm and one with the solution overlay, print a class set, and use as a bell-ringer, sub-day filler, or brain break. Older students can compare algorithms or use the size of the maze to practice estimation. The article above has more classroom ideas.
Can I download the maze as an image?
Yes. Use Download SVG for a crisp vector file that scales to any size without blurring (good for further editing or printing very large), or Download PNG for a flat image at 2× resolution (good for slides, blog posts, or sharing). Both files render black walls on white background regardless of the on-screen theme.
Can I play the maze online?
Yes. After generating a maze, click Play at the top of the result. A green marker appears at the start, and you can move it cell by cell with arrow keys, WASD, or the on-screen direction buttons (handy on a phone). Walls block movement. A timer starts on your first move and stops when you reach the exit; the tool remembers your best time per maze size in your browser. Click Restart to try again, or generate a new maze to start fresh.
Is my data private?
Yes. The generator runs entirely in your browser. There is no server-side processing, no analytics, no tracking. Nothing is sent, stored, or logged. You can verify by opening your browser's network tab while using the tool — nothing fires.