CSS shape-margin Property
Description
The shape-margin property controls an extra offset applied to a geometric shape used for wrapping inline content around an element. Instead of changing the element’s own box, it expands or contracts the shape that the layout engine uses to decide where text and other inline content are allowed to flow. This makes it possible to create a breathing room or an exclusion zone around irregular shapes (for example, images with non-rectangular silhouettes) without altering the element’s physical margins or position.
Commonly used in conjunction with shape-outside, shape-margin adjusts the effective boundary used for text wrapping so designers can tune spacing between the float’s visual outline and surrounding text. Because it operates on the wrapping shape rather than the element box, it is especially useful when you want consistent visual padding around a clipped or irregular image without changing layout metrics that other elements depend on. It also pairs well with clipping or masking techniques, for example when you combine it with clip-path to create a padded exclusion area around a clipped region.
Practical scenarios include keeping captions or labels from touching the edges of an irregular graphic, compensating for anti-aliased edges or drop shadows so wrapped text doesn’t appear too close, and fine-tuning the flow of multi-column text around floated artwork or decorative shapes. Because shape-margin only alters the wrapping shape, it won’t shift the float itself — if you need to move the element’s box you should use normal box-model properties like margin or positioning. When used alongside traditional floats (see float), it gives designers precise control over text flow without introducing layout side effects that direct margin changes can cause.
Be mindful that large offsets can significantly change line breaks and the overall flow of text; increasing the shape gap may force more wrapping or create larger empty areas in columns. Also, because it modifies the logical shape used for wrapping rather than content sizing, interactions with other layout features (such as float clearance behavior or text alignment) can produce subtle differences across complex layouts — so test visually and adjust the offset to achieve the intended balance between readability and design.
Definition
- Initial value
- 0
- Applies to
- Floats
- Inherited
- No
- Computed value
- as specified, but with relative lengths converted into absolute lengths
- Animatable
- Yes
- JavaScript syntax
- object.style.shapeMargin
Syntax
shape-margin = <length-percentage>
Values
- <length-percentage>Sets the margin of the shape to a <length> value or to a <percentage> of the width of the element's containing block.
Example
Browser Support
The following information will show you the current browser support for the CSS shape-margin property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
