HomeMathematicsSierpinski Carpet

🟪 Sierpinski Carpet

Explore the Sierpiński carpet, a recursive fractal made by dividing a square into a 3x3 grid and removing the center square at every level. Adjust iteration depth, invert the holes, and watch the subdivision animate.

Mathematics2DEasy60 FPS
sierpinski-carpet ↗ Open standalone

About this simulation

The Sierpiński carpet is built by taking a square, splitting it into a 3×3 grid of nine equal sub-squares, removing the center sub-square, and then repeating that same split-and-remove step inside every one of the eight squares that remain. Each additional level multiplies the number of filled squares by eight while shrinking the total filled area by a factor of 8/9, producing an intricate lattice of holes that is a foundational example of a self-similar fractal.

🔬 What it shows

A square is recursively subdivided into a 3×3 grid with the center removed at every level, down to the chosen iteration depth n. The simulation genuinely recurses through the geometry — at depth n there are exactly 8n filled sub-squares covering a fraction (8/9)n of the original area, both computed live and shown in the stats box.

🎮 How to use

Drag the iteration slider from 0 to 6 to change recursion depth, pick a fill color, and toggle Invert to reveal the removed center holes instead of the remaining structure. Switch Animate on to watch the subdivision reveal itself level by level, or off to draw the final pattern instantly; Replay restarts the animation and Reset restores the defaults.

💡 Did you know?

The Sierpiński carpet has a fractal dimension of log(8)/log(3) ≈ 1.893 — more than a line but less than a filled plane. It is also a "universal" plane curve: mathematicians have shown that every possible curve drawn in the plane without crossing itself can be found somewhere inside the carpet's structure.

Frequently asked questions

What is the Sierpiński carpet?

The Sierpiński carpet is a plane fractal formed by dividing a square into a 3×3 grid of nine equal sub-squares, removing the center one, and repeating the same process inside each of the eight remaining squares indefinitely. It was first described by the Polish mathematician Wacław Sierpiński in 1916.

How is the Sierpiński carpet different from the Sierpiński triangle?

The Sierpiński triangle removes the middle triangle from a triangle split into four parts, while the Sierpiński carpet removes the middle square from a square split into a 3×3 grid of nine parts. Both are classic self-similar fractals built by recursively deleting a central piece, but the carpet is based on squares and a 3×3 subdivision rather than triangles and a 2-way split.

How many squares remain after n iterations?

After n iterations there are exactly 8n filled sub-squares, because each subdivision step keeps 8 of the 9 squares in the grid and this happens independently inside every square that survived the previous level. At depth 3, for example, there are 83 = 512 squares.

What fraction of the area remains as the iteration increases?

Each level keeps 8/9 of the area that was present before it, so after n iterations the remaining area is (8/9)n of the original square. This fraction shrinks toward zero as n grows, even though the number of individual squares grows without bound, which is exactly the paradox that makes fractal dimension a useful idea.

What is the fractal dimension of the Sierpiński carpet?

Its Hausdorff dimension is log(8)/log(3), approximately 1.8928. This sits between the dimension of a simple curve (1) and a filled two-dimensional plane (2), reflecting how the carpet fills space more thoroughly than a line but leaves infinitely many holes so it never fills a full plane.

⚙ Under the hood

Recursively subdivide a square into a 3x3 grid, removing the center square at every level, to build the Sierpinski carpet fractal with live area/count stats.

fractalrecursiongeometrycanvas

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)