Programming & Data Processing

Sierpinski Carpet Generator: How to Create Fractals Online with Custom Depth and Colors

By WTools Team·2026-03-29·7 min read

Say you need a Sierpinski Carpet for a math class, a generative art piece, or a coding exercise. Writing the recursive rendering from scratch is a lot of work for what might be a five-minute need. The Sierpinski Carpet generator on wtools.com handles the boring parts so you can go straight to a usable fractal image, with controls for iteration depth, canvas size, and colors.

Below I'll walk through what the Sierpinski Carpet actually is, how the generator works, and what the different settings do.

What is the Sierpinski Carpet?

The Sierpinski Carpet is a plane fractal that Polish mathematician Wacław Sierpiński described in 1916. You start with a filled square. Divide it into a 3×3 grid of nine equal sub-squares, then remove the center one. Now do the same thing to each of the remaining eight sub-squares. Repeat forever.

After infinite iterations you get a set with a Hausdorff dimension of log 8 / log 3 ≈ 1.8928, which puts it somewhere between a line and a full plane. In practice, five or six iterations give you a pattern detailed enough for most visual and educational work.

Key properties

  • Self-similarity: Every sub-region of the carpet is a scaled-down copy of the whole.
  • Zero area: The total removed area approaches 100% of the original square as iterations go to infinity.
  • Fractal dimension: About 1.893. This number captures how the carpet fills space more than a line does but less than a solid square.
  • Universal plane curve: Every compact one-dimensional planar set is homeomorphic to a subset of the Sierpinski Carpet, making it a universal curve.

How iteration depth shapes the pattern

Iteration depth is the setting that matters most. Here's what each level gives you:

Iteration 0

A solid filled square, no subdivisions. Just a baseline.

Iteration 1

The square splits into a 3×3 grid and the center cell gets removed. You're left with 8 filled cells and 1 empty one.

Iteration 2

Each of those 8 filled cells subdivides again, removing 8 more center cells. That gives you 64 filled sub-cells and 9 total holes of varying sizes.

Iteration 3–6

Things grow fast from here. Iteration 3 has 512 filled cells; iteration 5 has over 32,000. Most screens can't resolve individual cells past iteration 6 at typical canvas sizes.

A good rule of thumb: match your iteration depth to your canvas size. A 729×729 canvas (3^6) maps perfectly to iteration 6 because each cell lands on exactly one pixel.

Step by step: generating a Sierpinski Carpet on wtools.com

Here's how to create your fractal using the tool at wtools.com:

  1. Open the tool. Go to wtools.com/math/generate-sierpinski-carpet.
  2. Set iteration depth. Pick a value between 0 and 6. If this is your first time, start with 3 or 4.
  3. Choose canvas size. Enter a width and height in pixels. Powers of 3 (81, 243, 729) give the cleanest results. A 729×729 canvas at iteration 6 produces pixel-perfect cells.
  4. Pick fill colors. Select a foreground color for the filled squares and a background color for the removed sections. High contrast combinations like black on white or neon on dark read well in presentations.
  5. Generate. Click the generate button. The fractal renders in your browser.
  6. Download or copy. Save the image for use in documents, slides, or code projects.

Example configurations

| Use Case | Depth | Canvas | Foreground | Background | |---|---|---|---|---| | Quick preview | 3 | 243×243 | Black | White | | Presentation slide | 5 | 729×729 | Navy | Light gray | | Generative art | 4 | 600×600 | Custom hex | Custom hex | | Pixel-perfect print | 6 | 729×729 | Black | White |

Why use an online fractal generator?

Coding a Sierpinski Carpet yourself is a solid recursion exercise, but plenty of situations call for an online tool instead:

  • Speed. No setup, no dependencies, no compile step. You go from idea to image in under 10 seconds on wtools.com.
  • Accessibility. Students, designers, and educators who don't write code can still generate fractals.
  • Consistency. The tool handles edge cases like non-power-of-3 canvas sizes gracefully, producing clean output every time.
  • Easy comparison. You can quickly try different depths and color schemes side by side without touching source code.

Practical use cases

Education and teaching

Math teachers use the Sierpinski Carpet to introduce recursion, fractal geometry, and the concept of dimension. Generating a carpet at each iteration level from 0 through 5 and displaying them side by side makes the recursive structure click immediately for students.

Generative art and design

Fractal patterns work well as textures, backgrounds, or structural elements. The color controls in the wtools.com generator let you produce on-brand fractal graphics without round-tripping through an image editor.

Programming reference

If you're building your own fractal renderer, you need a known-correct image to validate against. Generate a carpet at iteration 4 on wtools.com, then compare it pixel by pixel with your implementation's output.

Antenna and engineering research

Fractal antenna designers use the Sierpinski Carpet geometry because the self-similar structure enables multi-band frequency response. Researchers generate carpet patterns at specific iterations to model antenna geometries before running simulations.

3D modeling

The three-dimensional analog of the Sierpinski Carpet is the Menger Sponge. Generating the 2D carpet first helps you visualize the cross-section before extending the pattern into 3D modeling software.

Tips for best results

  • Match canvas to depth. A canvas size of 3^n pixels (where n equals your iteration depth) means each smallest cell is exactly one pixel. No aliasing.
  • Keep depth practical. Iteration 7 and beyond produce patterns too fine for most displays. Depth 5 or 6 covers nearly everything.
  • Use high contrast for print. If the image will be printed or projected, black and white gives you the most clarity.
  • Export at high resolution. If you need a large image, set the canvas to 729 or higher before generating. Upscaling a small image afterward always looks worse.

FAQ

What is the Sierpinski Carpet and who invented it?

The Sierpinski Carpet is a plane fractal built by recursively removing the center square from a 3×3 grid. Wacław Sierpiński, a Polish mathematician, described it in 1916. It's known for its self-similarity and has a Hausdorff dimension of about 1.893.

How does iteration depth affect the output?

Each iteration subdivides every filled cell into 9 parts and removes the center, so the number of filled cells multiplies by 8 each time. More depth means more detail but exponentially more cells. Depth 5 gives you 32,768 filled cells; depth 6 gives you 262,144. Past depth 6, individual cells are sub-pixel on most screens.

What canvas size should I choose for the sharpest image?

Use a power of 3 that matches your iteration depth. For depth 4, go with 81×81 or 243×243. For depth 6, use 729×729. That way every cell maps to whole pixels, which gives you the crispest rendering with no anti-aliasing artifacts.

What is the difference between the Sierpinski Carpet and the Sierpinski Triangle?

Both are self-similar fractals, but they start from different shapes and follow different subdivision rules. The Triangle divides an equilateral triangle into 4 smaller triangles and removes the center one, keeping 3. The Carpet divides a square into 9 sub-squares and removes the center one, keeping 8. The Carpet's fractal dimension (≈1.893) is higher than the Triangle's (≈1.585).

Can I use the generated image commercially?

The Sierpinski Carpet is a mathematical object, so it can't be copyrighted. Images you generate with the tool on wtools.com are yours to use however you want, whether that's personal, educational, or commercial.

What real-world applications use the Sierpinski Carpet pattern?

It shows up in fractal antenna design, MEMS (micro-electromechanical systems) engineering, digital art, architectural ornamentation, and educational materials. Antenna design is probably the most common engineering application, since the self-similar structure gives you multi-band frequency response.

Conclusion

The Sierpinski Carpet is one of the most recognizable fractals in mathematics, and you shouldn't need a full development environment to generate one. The fractal generator at wtools.com gives you control over iteration depth, canvas dimensions, and color, which is all you need for a clean carpet for teaching, design, research, or code validation. Set your depth, pick your colors, and hit generate.

Frequently Asked Questions

What is the Sierpinski Carpet and who invented it?

The Sierpinski Carpet is a plane fractal constructed by recursively removing the center square from a 3×3 grid. It was described by Polish mathematician Wacław Sierpiński in 1916. The pattern is notable for its self-similarity and its Hausdorff dimension of approximately 1.893.

How does iteration depth affect the output?

Each iteration subdivides every filled cell into 9 parts and removes the center, multiplying the number of filled cells by 8. Higher depth means more detail but exponentially more cells. Depth 5 produces 32,768 filled cells; depth 6 produces 262,144. Beyond depth 6, individual cells are sub-pixel on most screens.

What canvas size should I choose for the sharpest image?

Use a power of 3 that matches your iteration depth. For depth 4, use 81×81 or 243×243. For depth 6, use 729×729. This ensures that every cell maps to whole pixels, producing the crispest possible rendering without anti-aliasing artifacts.

What is the difference between the Sierpinski Carpet and the Sierpinski Triangle?

Both are self-similar fractals, but they start from different shapes and use different subdivision rules. The Triangle divides an equilateral triangle into 4 smaller triangles and removes the center one (keeping 3). The Carpet divides a square into 9 sub-squares and removes the center one (keeping 8). The Carpet has a higher fractal dimension (≈1.893) than the Triangle (≈1.585).

Can I use the generated image commercially?

The Sierpinski Carpet is a mathematical object and cannot be copyrighted. Images you generate using the tool on wtools.com are yours to use in personal, educational, or commercial projects without restriction.

What real-world applications use the Sierpinski Carpet pattern?

Fractal antenna design, MEMS (micro-electromechanical systems) engineering, digital art, architectural ornamentation, and educational materials all use Sierpinski Carpet geometry. The self-similar structure is particularly valuable in antenna design where multi-band frequency response is needed.

About the Author

W
WTools Team
Development Team

The WTools team builds and maintains 400+ free browser-based text and data processing tools. With backgrounds in software engineering, content strategy, and SEO, the team focuses on creating reliable, privacy-first utilities for developers, writers, and data professionals.

Learn More About WTools