Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Filters, Masks and Shapes

The shape-margin property

Reference for the CSS shape-margin property: add breathing room between a shape-outside shape and the text that wraps around it, with examples.

The shape-margin property pushes wrapped text away from the shape defined by shape-outside. The text moves outward by the given distance in every direction, following the outline of the shape rather than the box, so a circle gets a round margin.

Without it, text can touch the edge of the shape. Because the margin is applied to the shape, it works even when the float has no ordinary margin on that side.

CSS
.disc {
  float: left;
  shape-outside: circle(50%);
  shape-margin: 16px;
}

Try it

Zero versus 20px of shape margin

Syntax

CSS
shape-margin: <length-percentage [0,โˆž]>
  • Initial value: 0
  • Applies to: floats
  • Inherited: no
  • Animatable: yes (as a length or percentage)
  • Computed value: an absolute length, or a percentage as specified

Values

Value Description
<length> A non-negative distance such as 10px or 1rem.
<percentage> Relative to the width of the float's containing block, like margin percentages.

Negative values are not allowed.

Usage notes

  • Only for shapes. It is ignored when shape-outside is none. Ordinary margin still controls spacing around a float without a shape.
  • Margin follows the outline. For a polygon the offset runs perpendicular to each edge, rounded at the corners, which is hard to get with plain margins.
  • Does not affect the visible float. Only how text flows changes; the float itself and its background stay where they are.
  • Combine with an ordinary margin when you also want space on the side where the float meets the container's edge.
  • Percentages can surprise. They depend on the containing block's width, so a 10% margin grows and shrinks with the column.
  • Image shapes: the margin is added around the shape found by the alpha threshold. See shape-image-threshold.

Browser support

Supported together with shape-outside in all current major browsers.