Breaking text out of the rectangle

Every image, whatever its subject, arrives inside a box. By default, text sits above or below that box; float the image left or right and the text wraps the rectangle, ignoring whatever is inside it. shape-outside is the property that removes that constraint, letting a layout follow the contours of an image instead of its edges.

The property accepts an image's alpha channel — its transparent areas — as the source of the shape, so a guitar or a portrait can bend the text around itself. Straight-edged images beside solid blocks of text read as static; text that follows a curve introduces movement, brings image and copy into a shared composition, and slows readers slightly as they navigate the page.

A collage of three screenshots of Patty Melt's website side-by-side demonstrating the use of text flowing around image shapes.
Patty Meltt is an up-and-coming country music sensation.

Most guides to shape-outside begin with circles and polygons. That covers the how, but not the why, which is where the property becomes interesting to designers. The examples below come from a fictional brief: Patty Meltt, a country artist launching an album and a tour, needed a site that was distinctive and memorable, with a biography and a music section.

The mechanics, briefly

Text only flows around an element that is floated left or right and has a defined width. The URL passed to shape-outside points at an image with an alpha channel, such as a PNG or WebP. shape-image-threshold sets the alpha level at which the shape is generated, and shape-margin adds margin around the resulting shape.

img {
  float: left;
  width: 300px;
  shape-outside: url('patty.webp');
  shape-image-threshold: .5;
  shape-margin: 1rem;
}

A tall portrait in a two-column grid

Patty's life story splits into two parts — her biography and her music — so a tall vertical portrait serves the first and two smaller album covers the second. A simple grid creates the two columns.

An image of Patty staring into the camera on the left and two columns of white text on a black background on the right.
Columns without shape-outside applied to them
<section id="patty">
  <div>
    <img src="patty.webp" alt="">
    [...]
  </div>

  <div>
    <img src="album-1.webp" alt="">
    [...]
    <img src="album-2.webp" alt="">
    [...]
  </div>
</section>

To keep the design flexible, the column widths and margins are set in percentages rather than static pixels, so they scale with whatever the container's size turns out to be.

#patty {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 5rem;
}
#patty > *:nth-child(1) img {
  float: left;
  width: 50%;
  shape-outside: url("patty.webp");
  shape-margin: 2%;
}

#patty > *:nth-child(2) img:nth-of-type(1) {
  float: left;
  width: 45%;
  shape-outside: url("album-1.webp");
  shape-margin: 2%;
}

#patty > *:nth-child(2) img:nth-of-type(2) {
  float: right;
  width: 45%;
  shape-outside: url("album-2.webp");
  shape-margin: 2%;
}
Imager of Patty on the left and two columns of white text on a black background to the right. The second column of text flows around two images showing album covers.
Columns with shape-outside applied to them. See this example in my lab.

The text wraps Patty's image purely through its silhouette — no clipping paths, no polygons.

Silhouette of Patty's image on the left and two slightly rotated squares on the right that the text will flow around.
Building rotations into images.

One caveat: when an image is rotated with a CSS transform, browsers do not reflow text around the rotated alpha channel. In practice, the rotation usually has to be built into the image file itself.

Faking a centred image

Because floats have no center value, centring an image inside the text — a more striking treatment for the biography — requires an illusion. Patty's bio content is divided into two symmetrical columns, and the portrait is cut into two halves, each 50% of the original width.

Patty’s image set between two text columns. See this example in my lab.
#dolly {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
A silhouette of Patty's image with a dotted line dividing the image vertically against a transparent background.
Splitting the image into two pieces.

Each half sits in its own column, and each is floated toward the middle: the left column's half to the right, the right column's half to the left.

<section id="dolly">
  <div>
    <img src="patty-left.webp" alt="">
    [...]
  </div>
  
  <div>
    <img src="patty-right.webp" alt="">
    [...]
  </div>
</section>
#dolly > *:nth-child(1) img {
  float: right;
  width: 40%;
  shape-outside: url("patty-left.webp");
  shape-margin: 2%;
}
#dolly > *:nth-child(2) img {
  float: left;
  width: 40%;
  shape-outside: url("patty-right.webp");
  shape-margin: 2%;
}
Patty's image centered between two columns of white text flowing around it.
Faux-centred image. See this example in my lab.

The two halves meet in the centre, and the text appears to flow around both sides of a single image.

Text around a photograph with no hard cut-out

A tightly cut-out portrait with a clean alpha channel isn't always the right look; some designs should feel looser. For a section where the content had to flow around Patty and her guitar, the picture goes in as an inline image rather than a background-image, floated with a width of 100%.

Image of Patty sitting on a chair and playing an acoustic guitar. White text on a black background flows around it on the right.
Faux background image. See this example in my lab.
A large photo of Patty sitting on a chair playing an acoustic guitar. She is positioned slightly to the left of the frame.
Large featured image
<section id="kenny">
  <img src="patty.webp" alt="">
  [...]
</section>

One approach is to edit the image — strip away non-essential areas to produce a soft-edged alpha channel — then let shape-image-threshold decide which parts of that alpha become the wrapping contour. Because it is destructive and removes much of the texture behind Patty, that method was rejected here.

#kenny > img {
  float: left;
  width: 100%;
  max-width: 100%;
}
#kenny > img {
  shape-outside: url("patty.webp");
  shape-image-threshold: 2;
}

Instead, a polygon clip-path supplies the shape-outside value. The text flows around the polygon while the original image keeps all its detail.

The same image of Patty sitting in a chair playing an acoustic guitar. The right side has been removed following her shape, leaving a transparent area around her.
Edited image with a soft-edged alpha channel
#kenny > img {
  float: left;
  width: 100%;
  max-width: 100%;
  shape-outside: polygon(…);
  shape-margin: 20px;
}

Polygon points are rarely worth writing by hand; Bennett Feely's CSS clip-path maker does the work. Load the image, draw the shape, then copy the generated clip-path values into shape-outside.

A white dotted line shows the image's clipped area.
Original image with a non-destructive clip-path.

Flowing text between two shapes

For a design that pushes against convention the way Patty pushes against country music's, two photomontages sit above the content, their elements overlapping and spilling out of their containers to create depth. Each montage has an irregularly shaped alpha channel.

Editing the Patty image in Clippy, Bennett Feely’s CSS clip path maker.
Bennett Feely’s CSS clip path maker.
Two large montages of Patty with a column of white text on a background in between them, following the shapes.
Text between shapes. See this example in my lab.
Showing silhouettes of the irregularly shaped alpha channels against a transparent background.
Irregularly shaped alpha channels

The same image URLs used for the montages become the values of shape-outside, and the content flows between the two shapes down the page.

<section id="johnny">
  <img src="patty-1.webp" alt="">
  <img src="patty-2.webp" alt="">
  […]
</section>

What the property changes

Images in long-form content are too often boxed in and isolated, as if added as an afterthought. CSS Shapes, and shape-outside in particular, let images and text participate in one composition. That matters beyond usability: it shapes how the page feels. Text wrapping the curve of a guitar or the edge of a portrait makes a reader linger and turns an otherwise flat layout into something with rhythm and character.

Where a rectangle seems like the obvious container, it may be worth checking whether the image's own outline can carry the layout instead.