CSS Reference ยท Filters, Masks and Shapes
The shape-outside property
Reference for the CSS shape-outside property: wrap text around circles, polygons and image outlines instead of a rectangle, with live examples and notes.
The shape-outside property changes the shape that inline content wraps around when it flows beside a float. Normally text wraps around the float's rectangular margin box. With shape-outside it can follow a circle, an ellipse, a polygon, or the visible part of an image.
The property only affects text wrapping. It does not change how the float looks, so you usually combine it with clip-path or border-radius to make the visible shape match the wrapping shape.
.portrait { float: left; width: 140px; height: 140px; shape-outside: circle(50%); border-radius: 50%; }
Try it
Syntax
shape-outside: none | <basic-shape> || <shape-box> | <image> /* <shape-box>: margin-box | border-box | padding-box | content-box */
- Initial value:
none - Applies to: floats
- Inherited: no
- Animatable: yes, for basic shapes of the same type; not for images
- Computed value:
none, or the computed basic shape with lengths made absolute and the box if given, or the image with a computed URL
Values
| Value | Description |
|---|---|
none |
The float's margin box is used (normal wrapping). |
circle(), ellipse(), inset(), polygon() |
A basic shape. Percentages refer to the reference box. |
margin-box |
The float's margin box, with its rounded corners. This is the default reference box. |
border-box |
The edge of the border. |
padding-box |
The edge of the padding. |
content-box |
The edge of the content. |
<image> |
The shape is the area of the image where alpha is greater than shape-image-threshold. |
A box keyword alone wraps text along that box's edge, including border-radius rounding.
Usage notes
- Floats only. The property is ignored on elements that are not floated. Also give the float explicit width and height; a shape cannot be calculated for an empty, size-less box.
- Shape only affects text. The float itself still paints as a rectangle. Add
border-radius,clip-pathor a matching image so what people see matches how text wraps. - Use
shape-marginto keep text away from the shape. Seeshape-margin. - Images need CORS. An image used for
shape-outsidemust be same-origin or served with CORS headers, otherwise the shape is not applied. Gradients anddata:URLs avoid this problem. - Wrapping follows the line boxes. Narrow gaps are skipped: if the space beside the shape is too small for a word, the line moves down.
- Accessibility. Reading order is unchanged. Make sure that irregular wrapping doesn't create awkward line lengths on small screens, and consider disabling the shape in narrow layouts.
- Newer alternative.
shape-outsideonly works on floats; there is no equivalent for flex or grid items.
Browser support
Supported in current versions of all major browsers for basic shapes and box values; shapes taken from images depend on CORS, so test them on your real server.
Related
shape-marginโ distance between the shape and the textshape-image-thresholdโ the alpha cut-off for image shapesfloatโ required forshape-outsideto applyclip-pathโ draws the visible shape- Lessons: CSS Shapes, Floats