Organic shapes in CSS with shape()

Monotone geometry — rectangles, circles, rounded rectangles — is routine CSS. Triangles, hexagons, stars and hearts take more effort but remain straightforward with modern features. Shapes with real randomness and many curves are a different problem: wavy, wiggly, blob, squiggly, ragged, torn. Whatever the name, these usually live in the SVG world or arrive as images exported from design tools. The shape() function now lets us build them in CSS.

Building them by hand is still tricky; the math and calculations add up quickly. Daniel C. built a set of generators around the problem — a wavy divider generator, a fancy frame generator and a blob generator — and you can pull the code out after adjusting a few settings. A generator output is a starting point; knowing the underlying technique lets you hand-tune variations the tool does not expose.

The core rule: joining curves smoothly

All of the generated shapes share one technique: a chain of curve commands. The visual trick is making two adjacent curves share a tangent so the result reads as one continuous stroke.

What a single curve draws

One curve command, using a single control point, divides its segment like this:

A normal curve with a control point in the very center. The second shows another curve with control point veering towards the left, contorting the curve.

Placing two curves side by side

Two curves touch at a shared point: E1, the endpoint of the first, is S2, the start of the second. For the pair to read smoothly, E1/S2 must sit on the segment between C1 and C2, the two control points. Miss that criterion and the join becomes a visible kink.

A wavy curve with two control points, one point up and the other down forming a wave along three points.
A wavy curve with two control points. The second point is moved down and toward the right, bending the curves second wav in an undesired way.

The generative approach follows from there: randomly place consecutive curves while keeping every shared endpoint on the line between its neighbouring control points. For simplicity, treat that shared point as the midpoint of the two control points. Fewer degrees of randomness to manage, and the smoothness criterion is satisfied by construction.

From wavy edge to blob

The simplest variant is a wavy divider: randomness along one edge only.

A long blue rectangle with a jagged bottom edge.

Two variables drive the result. Granularity (an integer) is the number of curves. Size is the space the curves span.

The same blue renctangle in two versions with two different jagged bottom edges, marked in red to show the shape. The first is labeled Granularity 8 and the second, with more and deeper jags, is labeled Granularity 18.

Wavy dividers, step by step

  1. Create N points evenly along the bottom of the element.
A white rectangle with a black border and seven control points evenly spaced along the bottom edge.
  1. Offset each point vertically by a random value in the range [0 size].
A white rectangle with a black border and seven control points evenly spaced in a wavy formation along the bottom edge. A red label saying Size indicates the vertical height between the highest point and lowest point.
  1. Take adjacent pairs and compute their midpoints — a second, systematic set of points.
A white rectangle with a black border and thirteen control points evenly spaced in a wavy formation along the bottom edge. A red label saying Size indicates the vertical height between the highest point and lowest point. Every even point is marked in blue.

So there are two point sets: the randomly placed control points and the midpoints computed to respect the smooth-join rule. Drawing all curves through them yields the shape. In the CSS output, Ci denote the random control points and Pi the midpoints.

.shape {
  clip-path: shape(from Px1 Py1,
    curve to Px2 Py2 with Cx1 Cy1,
    curve to Px3 Py3 with Cx2 Cy2,
    /* ... */
    curve to Pxi Pyi with Cx(i-1) Cy(i-1)
    /* ... */
  )
}

The same logic extends to top, bottom and top-plus-bottom edges, or all sides at once.

A two-by-two grid of the same blue rectangle with different configurations of wavy edges. The first on the bottom, the second on the top, the third on the top and bottom, and the fourth all along the shape.

Going circular for blobs

Blobs follow a different mental model. Instead of a rectangle made of straight edges, the reference geometry is a circle. Points are spaced evenly around the circle formed by an element with border-radius: 50%, then randomly offset toward the center; adding the midpoints and drawing the curves completes the shape.

Two white circles with black borders that contain a smaller circle with a dashed border. The first circle has eight black control points around the outer circle evenly spaced. The second has 15 control points around it, even other one in blue and positioned between the outer and inner circles to form a wavy shape.
A large green blob shape.

Rounded-rectangle frames

Combining the two techniques — rectangular edges plus rounded corners — produces fancy frames. It is the hardest of the group to implement, since each corner and each side needs its own handling, and the segments can carry different granularities. The payoff is a wide range of frame variations.

A blue rounded rectangle next to another version of itself with a large number of jagged edges all around it.

Reusing shapes in compositions and animation

Four shapes copied straight out of the wavy divider generator — bottom configuration for the header, top for the footer, top plus bottom for the inner elements — cover a full classic layout. Animation is the next step; each animated element carries its own --s1 and --s2 shapes:

@media screen and (prefers-reduced-motion: no-preference) {
  .element {
    --s1: shape( ... );
    --s2: shape( ... );
    animation: dance linear 1.6s infinite alternate;
  }

  @keyframes dance {
    0% {clip-path: var(--s1)}
    to {clip-path: var(--s2)}
  }
}

Generate two shapes in the generator with the same granularity and different sizes, and the browser interpolates between them for a smooth, automatic animation. Swapping in animation-timeline: scroll() makes the animation scroll-driven with no further work.

A sticky header variant plays with size instead: keep granularity and shape ID fixed, use a size of 0 for the initial rectangular state and a non-zero size for the wavy state, and let the browser animate the transition. In general, shapes can either sit as static decoration, or you can animate between two or more by holding granularity constant and varying size and shape ID.

Examples worth borrowing from

Quick demonstrations built on these generators and techniques — hover, click, wobble and reveal:

These lean on the same two controls: granularity fixed, size and shape ID varied. They show the range of motion — grow, shrink, wobble, reveal — reachable without touching SVG.

For a final demonstration of scale, consider a CSS-only artwork in which each drawing is a single element with a single shape() rule. The code was produced with an SVG-to-CSS converter and other tooling, but the result is a striking demonstration that complex curved artwork can be produced entirely in CSS.