CSS Shapes: shape-outside, shape-margin and Non-Rectangular Text Wrap
Wrapping text around circles, polygons, rounded boxes and images instead of rectangles: shape-outside values, the reference box, shape-margin, image and gradient shapes with shape-image-threshold, pairing shapes with clip-path, and where shapes are limited.
kvi5hnuCode Sprout team member7 min readOn this page
A float pushes text aside along a rectangle: its margin box. With shape-outside, you give the float a different outline for wrapping, such as a circle, an angled edge or the outline of a cut-out photo, and the lines follow that shape. It's a magazine technique that works well for pull quotes, author photos and editorial layouts.
shape-outside only affects how surrounding content wraps. It doesn't change how the float itself looks: the element is still drawn as a rectangle. To make it look like the shape too, clip it with clip-path (article 100) or border-radius.
A first shape
.author {
float: inline-start;
inline-size: 10rem;
aspect-ratio: 1;
border-radius: 50%; /* looks round */
shape-outside: circle(50%); /* text wraps round */
shape-margin: 1rem; /* space between the circle and the text */
}
Key rules:
- Floats only.
shape-outsidehas no effect on any other element. - The float needs a size. Shapes are computed from the float's box, so give it a width and a height or ratio.
- The shape is clipped to the margin box. Text can wrap in closer than the box, but never further out. A shape larger than the box, or a
shape-marginthat reaches past it, is cut at the margin box's edge.
Shape values
| Value | Shape |
|---|---|
none (initial) | the float's margin box: ordinary wrapping |
margin-box, border-box, padding-box, content-box | that box, including its border-radius |
circle(r at x y) | a circle; circle() alone is a circle touching the nearest sides, centered |
ellipse(rx ry at x y) | an ellipse |
inset(top right bottom left round radius) | a rectangle inset from the box's edges, optionally rounded |
polygon(x1 y1, x2 y2, ...) | any polygon, with points as lengths or percentages |
path("...") | an SVG path, in pixels; Chrome 149 and Safari 27.3 |
shape(...) | the newer responsive path syntax, which accepts percentages; parses for shape-outside in current Chrome |
url(...) or a gradient | an image whose transparent pixels define the shape |
Basic shapes are measured against a reference box, by default the margin box. You can name another after the shape: polygon(...) content-box. For box values alone, border-box with a border-radius gives rounded wrapping with no shape function at all.

The float is the same 110 × 110 box in every panel; only shape-outside changes, and the lines follow its edge.
Polygons
Polygon points are pairs of x and y coordinates, as lengths or percentages of the reference box, listed clockwise or counterclockwise:
.angled {
float: inline-start;
inline-size: 45%;
block-size: 18rem;
shape-outside: polygon(0 0, 100% 0, 60% 100%, 0 100%); /* a slanted right edge */
clip-path: polygon(0 0, 100% 0, 60% 100%, 0 100%); /* the same shape for the visual */
}
Using the same value in both properties keeps the visual and the wrapping in sync. A custom property avoids repeating it: --shape: polygon(...), then shape-outside: var(--shape); clip-path: var(--shape);.
Firefox's DevTools have a shapes editor that draws the polygon on the page and lets you drag its points, and Chrome's show the shape outline when you select the element.
Images and gradients as shapes
With an image, the shape comes from the image's alpha channel: text wraps around the parts that aren't transparent. A PNG or WebP of a product photographed on a transparent background makes text hug its outline:
.vase {
float: inline-end;
inline-size: 14rem;
shape-outside: url("vase.png");
shape-image-threshold: 0.5; /* pixels more than 50% opaque count as the shape */
shape-margin: 0.75rem;
}
shape-image-threshold, from 0 (the initial value) to 1, sets how opaque a pixel must be to count as part of the shape. With a soft-edged image or a gradient, a higher threshold lets text move further into the faded area.- Images from another origin must be served with CORS headers, or the browser ignores the shape and falls back to the margin box. This is a common reason an image shape silently doesn't work.
- The image is only used for the shape; you still need to show it, usually as the
<img>that is floated, or as its background.
Gradients are images too, and don't need a download. A hard-edged linear gradient makes an angled edge, and a radial gradient a circle or ellipse:
.diagonal {
float: inline-start;
inline-size: 60%;
block-size: 16rem;
shape-outside: linear-gradient(75deg, black 55%, transparent 55%);
}
body { font: 0.82rem/1.5 Georgia, serif; margin: 1rem; }
p { margin: 0; text-align: justify; hyphens: auto; }
section { display: flow-root; margin-bottom: 0.75rem; } /* each float stays in its section */
.avatar {
float: left;
inline-size: 7rem; aspect-ratio: 1;
border-radius: 50%;
background: radial-gradient(circle at 35% 35%, #f4c95d, #8a3b12);
shape-outside: circle(50%);
shape-margin: 0.6rem;
margin-inline-end: 0.6rem; /* shape-margin can't reach past the margin box */
}
.slope {
float: left;
inline-size: 55%; block-size: 9rem;
margin-block: 0.25rem;
--edge: linear-gradient(70deg, black 45%, transparent 45%);
background: #2f7d4f;
mask-image: var(--edge);
shape-outside: var(--edge);
shape-margin: 0.5rem;
}
.tri {
--shape: polygon(0 0, 100% 50%, 0 100%);
float: left;
inline-size: 6.5rem; block-size: 8rem;
background: #8a3b12;
clip-path: var(--shape);
shape-outside: var(--shape);
shape-margin: 0.4rem;
}
shape-margin
shape-margin adds space along the contour of the shape, like a margin that follows the curve. A plain margin on the float only pushes the rectangular margin box out, which doesn't help where the curve is inside the box. Since the shape is clipped to the margin box, a shape-margin only works where the box has room for it: on a full circle that touches the box's edges, the text at the top and bottom follows the curve, but beside the circle's widest point it stops at the box edge. Give the float a matching regular margin on the wrapping side, or make the shape a bit smaller than the box.

The first two panels give the float a real margin first: shape-margin can only grow the shape within the margin box, as the last panel shows.
Limits
- Shapes only affect the side of the float where text wraps. Text never wraps on both sides of a float.
shape-inside, for wrapping text inside a shape, was proposed but isn't in any browser.- Very narrow spaces between a shape and the column edge produce short, ragged lines.
text-align: justifywithhyphens: autohelps, but test at narrow widths, and remove the float on small screens as in article 54. - Shapes are purely visual. Screen readers read the text in source order, unaffected.
What's current
shape-outsidewith basic shapes, box values and images works in all browsers.path()inshape-outside: Chrome 149 and Safari 27.3, not Firefox.rect()andxywh(): all browsers since 2026.- The
shape()function is Baseline since February 2026 forclip-path; check support before relying on it inshape-outside.
Common questions
Why doesn't my shape-outside do anything?
The element isn't floated, it has no size, or the shape is bigger than its margin box. For image shapes, a cross-origin image without CORS headers is ignored.
Why does my float still look square?
shape-outside only changes the wrapping. Add border-radius or clip-path for the visual.
Can text wrap on both sides of a shape? No. Floats wrap content on one side only.
Why doesn't shape-margin add space beside the widest part of my circle?
The shape, including its margin, is clipped to the float's margin box. Add a normal margin on the text side, or shrink the circle.
Can I use the same shape for clipping and wrapping?
Yes. Put the shape in a custom property and use it for both clip-path and shape-outside.
Summary
shape-outsidegives a float a non-rectangular outline for wrapping; it doesn't change how the float looks.- It works only on floats with a size, and the shape is clipped to the margin box.
- Values: box keywords (with
border-radius),circle(),ellipse(),inset(),polygon(),path()and images or gradients. shape-image-thresholdsets the opacity that counts as the shape; cross-origin images need CORS.shape-marginadds space along the contour, within the margin box.- Reuse the shape for
clip-pathwith a custom property.
Practice questions
Write CSS for a floated 12rem round photo that text wraps around, with 1rem of space along the curve.
Answer
.photo {
float: inline-start;
inline-size: 12rem;
aspect-ratio: 1;
border-radius: 50%;
shape-outside: circle(50%);
shape-margin: 1rem;
margin-inline-end: 1rem; /* room for the shape margin beside the widest point */
}
A product image from a CDN on another domain is used as shape-outside: url(...), but text wraps around a rectangle. What's the likely cause?
Answer
The image is cross-origin and isn't served with CORS headers, so the browser can't read its pixels and falls back to the margin box.
What does shape-image-threshold: 0.8 change for a shape made from a soft gradient?
Answer
Only pixels more than 80% opaque count as part of the shape, so text moves further into the faded part of the gradient than with the default 0.
Why does this shape have no effect?
.badge { shape-outside: circle(50%); inline-size: 8rem; aspect-ratio: 1; }
Answer
The element isn't floated. shape-outside only applies to floats: add float: inline-start or float: inline-end.
Previous: Floats and Clearing: Wrapping Text Around Content
Next: Positioning: relative, absolute, Offsets, inset and the Containing Block

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.