Staaarter

Generate a Sierpinski Triangle

Generates the classic Sierpinski triangle by recursively subdividing a filled equilateral triangle into three sub-triangles at each level and discarding the middle piece, rendering the result as downloadable SVG filled-shape art. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
fractalgeneratorsvg

Overview

Introduction

The Sierpinski triangle is one of the most recognizable fractals in mathematics, a triangle that, when you recursively remove the middle piece from every remaining sub-triangle, approaches a shape with zero area but infinite detail. This tool renders it as filled, downloadable SVG shapes.

Enter a depth and the tool recursively subdivides a starting triangle that many levels, discarding the middle sub-triangle at every step, then draws every surviving smallest sub-triangle as a filled polygon.

What Is Generate a Sierpinski Triangle?

A real, classic fractal, also called the Sierpinski gasket or Sierpinski sieve, formed by starting with a solid triangle and repeatedly removing the triangle formed by connecting the midpoints of each remaining triangle's edges.

This tool builds it via direct recursive triangle subdivision, working with the triangle's corner coordinates directly, rather than the turtle-graphics zigzag path the Sierpinski Arrowhead Curve Generator uses. Both constructions converge on the same limiting shape.

How Generate a Sierpinski Triangle Works

Starting from one equilateral triangle, the generator finds the midpoint of each of its three edges, which together define a smaller central triangle.

That central triangle is discarded, and the three remaining corner sub-triangles (each half the size of the parent) are recursed into using the same rule, down to the depth you enter.

At the deepest level, every surviving small triangle is emitted as a filled polygon; those polygons are then rescaled to fit the SVG viewbox and rendered together as the finished fractal.

When To Use Generate a Sierpinski Triangle

Use it whenever you want the classic filled Sierpinski triangle look, for generative art, educational diagrams, textile or tiling patterns, or any design needing a recognizable recursive-triangle motif.

It's a clear teaching example of recursive geometric subdivision, each level's rule is simple (keep three corners, discard the middle) but the compounding effect after several levels is what produces the fractal's self-similar detail.

If you want the same overall triangular pattern traced as a single continuous line instead of filled shapes, use the Sierpinski Arrowhead Curve Generator instead.

Features

Advantages

  • A well-documented, classic fractal with a single, unambiguous construction, not an invented variant.
  • Filled-polygon rendering makes the fractal's self-similar structure immediately readable, even at low depths.
  • Downloadable as both SVG (for further vector editing) and PNG (for quick use anywhere).

Limitations

  • Triangle count triples with every added depth level, so the range is capped at depth 8 to keep rendering and downloads responsive.
  • At higher depths the smallest triangles become tiny relative to the overall shape, and browser rendering can slow down as the polygon count grows into the thousands.

Examples

Zero depth

Input

Depth: 0

Output

One solid filled triangle, no subdivision applied yet.

At depth 0 the recursion hasn't run, so the output is just the starting triangle.

Default depth

Input

Depth: 5

Output

A dense arrangement of small filled triangles clearly showing the classic Sierpinski gasket pattern.

The default of 5 shows several levels of nested self-similar detail while staying quick to render and download.

Best Practices & Notes

Best Practices

  • Start around depth 2 or 3 to see the subdivide-and-discard rule clearly before increasing toward the finer, more detailed higher end of the range.
  • Download the SVG rather than the PNG if you plan to recolor, scale, or further edit the shapes, vector output has no resolution limit.

Developer Notes

Implemented as direct recursive geometry, not an L-system: subdivideTriangle() takes a triangle's three corner points, computes the three edge midpoints, and recurses into the three corner sub-triangles (skipping the middle one) until depth reaches 0, at which point the surviving triangle is pushed as a Polygon. The starting triangle is fixed at (0,0), (100,0), (50,86.6) before normalizeGeometry() rescales everything to the shared SVG viewbox, matching the pattern every polygon-based fractal tool in this category uses (see recursive-fractal-generators.ts).

Generate a Sierpinski Triangle Use Cases

  • Educational diagrams demonstrating recursive geometric subdivision and self-similarity
  • Generative art, textile, and tiling patterns built from the classic Sierpinski gasket shape
  • Downloadable SVG shape art for design projects referencing a well-known fractal

Common Mistakes

  • Expecting a single continuous outline; this tool renders filled, separate polygons, for a one-stroke traced version of the same overall pattern use the Sierpinski Arrowhead Curve Generator.
  • Setting depth to the maximum right away; past depth 6 or so the individual triangles become small enough that added detail is hard to see without zooming into the downloaded SVG.

Tips

  • Compare directly against the Sierpinski Arrowhead Curve Generator at a similar iteration count to see how the filled-subdivision and traced-curve methods converge on the same overall shape.
  • Compare against the Sierpinski Carpet Generator to see the same middle-removal idea applied to a square grid instead of a triangle.

References

Frequently Asked Questions