Final time, I requested, “Why achieve this many long-form articles really feel visually flat?” I defined that:
“Photographs in long-form content material can (and sometimes ought to) do greater than illustrate. They will form how individuals navigate, interact with, and interpret what they’re studying. They assist set the tempo, affect how readers really feel, and add character that phrases alone can’t at all times convey.”
Then, I touched on the expressive potentialities of CSS Shapes and the way, through the use of shape-outside
, you may wrap textual content round a picture’s alpha channel so as to add power to a design and preserve it feeling full of life.
There are such a lot of inventive alternatives for utilizing shape-outside
that I’m stunned I see it used so not often. So, how will you use it so as to add persona to a design? Right here’s how I do it.
My transient: Patty Meltt is an up-and-coming nation music sensation, and she or he wanted a web site to launch her new album and tour. She needed it to be distinctive-looking and memorable, so she referred to as Stuff & Nonsense. Patty’s not actual, however the challenges of designing and growing websites like hers are.
Most shape-outside
guides begin with circles and polygons. That’s helpful, however it solutions solely the how. Designers want the why — in any other case it’s simply one other CSS property.
No matter form its topic takes, each picture sits inside a field. By default, textual content flows above or beneath that field. If I float a picture left or proper, the textual content wraps across the rectangle, no matter what’s inside. That’s the limitation shape-outside
overcomes.
shape-outside
helps you to break away from these bins by enabling layouts that may reply to the contours of a picture. That shift from photos in bins to letting the picture content material outline the composition is what makes utilizing shape-outside
so attention-grabbing.
Stable blocks of textual content round straight-edged photos can really feel static. However textual content that bends round a guitar or curves round a portrait creates motion, which might make a narrative extra compelling and fascinating.
CSS shape-outside
allows textual content to circulate round any customized form, together with a picture’s alpha channel (i.e., the clear areas):
img {
float: left;
width: 300px;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/patty.webp");
shape-image-threshold: .5;
shape-margin: 1rem;
}
First, a fast recap.
For textual content to circulate round parts, they should float
both left or proper and have their width
outlined. The shape-outside
URL selects a picture with an alpha channel, corresponding to a PNG or WebP. The shape-image-threshold
property units the alpha channel threshold for making a form. Lastly, there’s the shape-margin
property which — consider it or not — creates a margin across the form.
Interactive examples from this text are obtainable in my lab.
A number of picture shapes
Once I’m including photos to a long-form article, I ask myself, “How can they assist form somebody’s expertise?” Flowing textual content round photos can sluggish individuals down a little bit, making their expertise extra immersive. Visually, it brings textual content and picture into a more in-depth relationship, making them really feel a part of a shared composition somewhat than remoted parts.

shape-outside
utilized to themPatty’s life story — from singing in honky-tonks to headlining stadiums — incorporates two sections: one about her, the opposite about her music. I added a tall vertical picture of Patty to her biography and two smaller album covers to the music column:
[...]
[...]
[...]
A easy grid then creates the 2 columns:
#patty {
show: grid;
grid-template-columns: 2fr 1fr;
hole: 5rem;
}
I prefer to make my designs as versatile as I can, so as an alternative of specifying picture widths and margins in static pixels, I opted for percentages on these column widths so their precise measurement is relative to regardless of the measurement of the container occurs to be:
#patty > *:nth-child(1) img {
float: left;
width: 50%;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/patty.webp");
shape-margin: 2%;
}
#patty > *:nth-child(2) img:nth-of-type(1) {
float: left;
width: 45%;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/album-1.webp");
shape-margin: 2%;
}
#patty > *:nth-child(2) img:nth-of-type(2) {
float: proper;
width: 45%;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/album-2.webp");
shape-margin: 2%;
}

shape-outside
utilized to them. See this instance in my lab.Textual content now flows round Patty’s tall picture with out clipping paths or polygons — simply the pure silhouette of her picture shaping the textual content.

When a picture is rotated utilizing a CSS remodel
, ideally, browsers would reflow textual content round its rotated alpha channel. Sadly, they don’t, so it’s usually needed to construct that rotation into the picture.
shape-outside
with a faux-centred picture
For textual content to circulate round parts, they have to be floated both to the left or proper. Putting a picture within the centre of the textual content would make Patty’s biography design extra placing. However there’s no heart
worth for floats, so how would possibly this be doable?

Patty’s bio content material is break up throughout two symmetrical columns:
#dolly {
show: grid;
grid-template-columns: 1fr 1fr;
}
To create the phantasm of textual content flowing round either side of her picture, I first break up it into two components: one for the left and the opposite for the suitable, each of that are half, or 50%, of the unique width.

Then I positioned one picture within the left column, the opposite in the suitable:
[...]
[...]
To offer the phantasm that textual content flows round either side of a single picture, I floated the left column’s half to the suitable:
#dolly > *:nth-child(1) img {
float: proper;
width: 40%;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/patty-left.webp");
shape-margin: 2%;
}
…and the suitable column’s half to the left, in order that each halves of Patty’s picture mix proper within the center:
#dolly > *:nth-child(2) img {
float: left;
width: 40%;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/patty-right.webp");
shape-margin: 2%;
}

Fake background picture
To date, my designs for Patty’s biography have included a cut-out portrait with a clearly outlined alpha channel. However, I usually must make a design that feels looser and extra pure.

Ordinarily, I might place an image as a background-image
, however for this design, I needed the content material to circulate loosely round Patty and her guitar.

So, I inserted Patty’s image as an inline picture, floated it, and set its width to 100%;
[...]
#kenny > img {
float: left;
width: 100%;
max-width: 100%;
}
There are two strategies I would use to circulate textual content round Patty and her guitar. First, I would edit the picture, eradicating non-essential components to create a soft-edged alpha channel. Then, I might use the shape-image-threshold
property to manage which components of the alpha channel kind the contours for textual content wrapping:
#kenny > img {
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/patty.webp");
shape-image-threshold: 2;
}

Nevertheless, this technique is damaging, since a lot of the feel behind Patty is eliminated. As a substitute, I created a polygon clip-path
and utilized that because the shape-outside
, round which textual content flows whereas preserving all of the element of my authentic picture:
#kenny > img {
float: left;
width: 100%;
max-width: 100%;
shape-outside: polygon(…);
shape-margin: 20px;
}

clip-path
.I’ve little time for writing polygon path factors by hand, so I depend on Bennett Feely’s CSS clip-path maker. I add my picture URL, draw a customized polygon form, then copy the clip-path
values to my shape-outside
property.

Textual content between shapes
Patty Meltt likes to push the boundaries of nation music, and I needed to do the identical with my design of her biography. I deliberate to circulate textual content between two photomontages, the place parts overlap and components of the photographs spill out of their containers to create depth.

So, I made two montages with irregularly formed alpha channels.

I positioned each photos above the content material:
[…]
…and used those self same picture URLs as values for shape-outside
:
#johnny img:nth-of-type(1) {
float: left;
width: 45%;
shape-outside: url("https://css-tricks.com/getting-creative-with-shape-outside/patty-1.webp");
shape-margin: 2%;
}
#johnny img:nth-of-type(2) {
float: proper;
width: 35%;
shape-outside: url("img/patty-2.webp");
shape-margin: 2%;
}
Content material now flows like a river in a rustic track, between the 2 picture montages, filling the design with power and motion.
Conclusion
Too usually, photos in long-form content material find yourself boxed in and remoted, as in the event that they had been dropped into the web page as an afterthought. CSS Shapes — and particularly shape-outside
— give us an opportunity to deal with photos and textual content as a part of the identical composition.
This issues as a result of design isn’t nearly making issues usable; it’s about shaping how individuals really feel. Wrapping textual content across the curve of a guitar or the sting of a portrait slows readers down, invitations them to linger, and makes their expertise extra immersive. It brings rhythm and persona to layouts which may in any other case really feel flat.
So, subsequent time you attain for a rectangle, pause and take into consideration how shape-outside
may also help flip an peculiar web page into one thing memorable.