The shape-margin
CSS property sets a margin for a CSS shape created using shape-outside
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The margin lets you adjust the distance between the edges of the shape (the float element) and the surrounding content.
Syntax
/* <length> values */ shape-margin: 10px; shape-margin: 20mm; /* <percentage> value */ shape-margin: 60%; /* Global values */ shape-margin: inherit; shape-margin: initial; shape-margin: unset;
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.
Formal definition
Initial value | 0
|
Applies to | floats |
Inherited | no |
Percentages | refer to the width of the containing block |
Computed value | as specified, but with relative lengths converted into absolute lengths |
Animation type | a length, percentage or calc(); |
Formal syntax
<length-percentage>where <length-percentage> = <length> | <percentage>
Examples
Adding a margin to a polygon
HTML
<section>
<div class="shape"></div>
We are not quite sure of any one thing in biology; our knowledge of geology
is relatively very slight, and the economic laws of society are
uncertain to every one except some individual who attempts to set them
forth; but before the world was fashioned the square on the hypotenuse
was equal to the sum of the squares on the other two sides of a right
triangle, and it will be so after this world is dead; and the inhabitant
of Mars, if he exists, probably knows its truth as we know it.</section>
CSS
section {
max-width: 400px;
}
.shape {
float: left;
width: 150px;
height: 150px;
background-color: maroon;
clip-path: polygon(0 0, 150px 150px, 0 150px);
shape-outside: polygon(0 0, 150px 150px, 0 150px);
shape-margin: 20px;
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Shapes Module Level 1The definition of 'shape-margin' in that specification. | Candidate Recommendation | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
shape-margin
|
Chrome
Full support 37 |
Edge
Full support 79 |
Firefox Full support 62 Full support 62 No support 61 — 62 Disabled' From version 61 until version 62 (exclusive): this feature is behind the |
IE
No support No |
Opera
Full support 24 |
Safari Full support 10.1 Full support 10.1 Full support 10.1 Prefixed' Implemented with the vendor prefix: -webkit- |
WebView Android
Full support 37 |
Chrome Android
Full support 37 |
Firefox Android Full support 62 Full support 62 No support 61 — 62 Disabled' From version 61 until version 62 (exclusive): this feature is behind the |
Opera Android
Full support 24 |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 3.0 |
Legend
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
See also
shape-margin by Mozilla Contributors is licensed under CC-BY-SA 2.5.