πŸŒ€ Mastering shape-outside in CSS

πŸ“Œ What Is shape-outside?

The shape-outside property allows you to define a custom shape that controls how inline content (like text) wraps around a floated element.
Instead of wrapping text around a plain rectangle, you can make it flow around a circle, polygon, or even an image’s alpha channel.
This gives you magazine-style layouts, creative storytelling sections, and dynamic content flow. πŸ“°βœ¨

>>β€œshape-outside lets text dance around shapes β€” creating true editorial-quality layouts.”

🧩 Basic Requirements

⚠️ The element using shape-outside must be floatedβ†’ float: left; or float: right;
Otherwise, the shape won’t affect text flow.

🧩 Basic Syntax

Syntax

shape-outside: <basic-shape> | <image> | <shape-box>;

shape-outside: circle(50%);
shape-outside: polygon(0 0, 100% 0, 100% 100%);
shape-outside: url(image.png);
shape-outside: inset(20px);

βœ” Shapes include: circle(), ellipse(), inset(), polygon()
βœ” Images use their alpha channel to define wrap boundaries
βœ” shape-margin adds spacing around the shape

🎯 The shape-outside β€œFlow Rule”

Text wraps outside the defined shape. If using an image, only non-transparent regions define the shape.

πŸ§ͺ Example: Circle Text Wrap

Circle wrap

.circle {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: circle(50%);
  clip-path: circle(50%);  /* Optional: make visual shape match */
  background: url(profile.jpg) center/cover;
}

βœ” Perfect for profile pictures in blog layouts
βœ” clip-path makes the visible shape match the wrapping shape (recommended)

πŸ§ͺ Example: Polygon Wrap

Polygon wrap

.triangle {
  float: right;
  width: 200px;
  height: 200px;
  shape-outside: polygon(50% 0, 0 100%, 100% 100%);
  background: coral;
}

βœ” Text flows around a triangle β€” great for bold layouts.

πŸ§ͺ Example: Using Images as Shapes

Image-based shape

.mask-shape {
  float: left;
  width: 220px;
  height: 220px;
  shape-outside: url(star.png);
  shape-margin: 10px;
  background: url(star.png) center/contain no-repeat;
}

βœ” PNG or SVG with transparency defines how text flows
βœ” shape-margin gives breathing room around the star

🎨 Example: Heart-Shaped Text Flow

Heart wrap

.heart {
  float: right;
  width: 250px;
  height: 250px;
  shape-outside: path("M50,15 Q25,0 0,30 T50,60 T100,30 Q75,0 50,15 Z");
  clip-path: path("M50,15 Q25,0 0,30 T50,60 T100,30 Q75,0 50,15 Z");
}

βœ” Organic shapes
βœ” Beautiful for storytelling, magazine layouts, product designs

🧠 shape-margin β€” Your Best Friend

shape-margin example

shape-margin: 20px;

βœ” Adds spacing between text and the wrap shape
βœ” Prevents text from touching edges

πŸ”₯ Advanced Example: Irregular Image Wrap

Irregular wrap

.irregular {
  float: left;
  width: 300px;
  height: 300px;
  shape-outside: url(tree.png);
  shape-margin: 15px;
  background: url(tree.png) center/cover no-repeat;
}

βœ” Text wraps around the non-transparent silhouette of the image
βœ” Stunning for nature or artistic layout designs

🌈 Example: Combining clip-path + shape-outside

Consistent visual + wrap shape

.combined {
  float: left;
  width: 250px;
  height: 250px;
  shape-outside: circle(50%);
  clip-path: circle(50%);
}

βœ” clip-path controls visible shape
βœ” shape-outside controls text flow shape
βœ” Together they create perfectly matched visuals

πŸ”§ Browser Support

  • βœ” Chrome
  • βœ” Safari
  • βœ” Edge
  • ⚠️ Firefox: partial support (no image shapes)

Note

For maximum compatibility, use basic shapes like circle(), polygon(), inset().

πŸ› οΈ Debugging Tips

  • If shape-outside has no effect β†’ ensure the element is floated!
  • Set explicit width & height on the shape element
  • Use shape-margin for better text spacing
  • Use clip-path alongside for visual alignment
  • Try different values in DevTools for fine-tuning shape points

πŸ”— Helpful Tools & Resources

>>β€œshape-outside transforms plain paragraphs into art β€” guiding text with personality and flow.” 🌊✨