🧊 Menger Sponge
Explore the Menger sponge, a recursive 3D fractal built by dividing a cube into 27 sub-cubes and removing the center cube and the six face-center cubes at every level. Adjust recursion depth, toggle wireframe, and rotate the fractal in 3D.
About this simulation
The Menger sponge is built by taking a cube, splitting it into a 3×3×3 grid of twenty-seven equal sub-cubes, removing the single center sub-cube plus the six sub-cubes at the middle of each face, and then repeating that same split-and-remove step inside every one of the twenty cubes that remain. Each additional level multiplies the number of filled cubes by twenty while shrinking the total filled volume by a factor of 20/27, producing an intricate lattice of tunnels that is one of the most famous three-dimensional fractals.
🔬 What it shows
A cube is genuinely recursed through a 3×3×3 subdivision, removing the center and six face-center sub-cubes at every level, down to the chosen recursion depth n. At depth n there are exactly 20n filled sub-cubes covering a fraction (20/27)n of the original volume, both computed live and rendered with a single instanced mesh for performance, then shown in the stats box.
🎮 How to use
Drag the recursion level slider from 0 to 3 to change the depth of the fractal, switch between Solid and Wireframe rendering, and toggle Autorotate to spin the camera automatically. Drag to orbit manually, scroll or pinch to zoom, and use Reset camera to return to the default view.
💡 Did you know?
The Menger sponge has a fractal dimension of log(20)/log(3) ≈ 2.727 — more than a flat plane but less than a filled solid. As recursion increases, its volume shrinks toward zero while its surface area grows without bound, approaching a shape with essentially infinite surface enclosing essentially no volume.
Frequently asked questions
What is a Menger sponge?
The Menger sponge is a three-dimensional fractal formed by dividing a cube into a 3×3×3 grid of twenty-seven equal sub-cubes, removing the center sub-cube and the six sub-cubes at the center of each face, and repeating the same process inside each of the twenty remaining sub-cubes indefinitely. It was first described by the Austrian-American mathematician Karl Menger in 1926.
How is the Menger sponge constructed?
Starting from a solid cube, it is split into twenty-seven smaller cubes arranged in a 3×3×3 grid. The one cube exactly in the center and the six cubes centered on each face are removed, leaving the twenty cubes at the corners and edges of the grid. The same subdivide-and-remove rule is then applied again inside each of those twenty cubes, and so on for every subsequent level.
How many cubes remain after n iterations?
After n iterations there are exactly 20n filled sub-cubes, because each subdivision step keeps 20 of the 27 cubes in the grid and this happens independently inside every cube that survived the previous level. At depth 3, for example, there are 203 = 8,000 cubes.
What happens to the volume and surface area as the recursion increases?
Each level keeps 20/27 of the volume that was present before it, so after n iterations the remaining volume is (20/27)n of the original cube, shrinking toward zero as n grows. At the same time, every removal step exposes new interior faces, so the total surface area of the sponge actually increases without bound, even as its volume vanishes.
What is the fractal dimension of the Menger sponge?
Its Hausdorff dimension is log(20)/log(3), approximately 2.7268. This sits between the dimension of a flat plane (2) and a solid filled cube (3), reflecting how the sponge fills space more thoroughly than any flat surface but leaves infinitely many holes so it never fills a complete solid volume.
The canonical 3D fractal: subdivide each cube into 27 children and keep 20, recurse. Rendered as a GLSL raymarched SDF with iteration level 0–5, surface area and Hausdorff dimension log20/log3.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install