The inset()
function defines a rectangle. This may not seem very useful as floating an item, without shapes, will give you a rectangular shape around it. However, the inset()
type enables the definition of offsets, thus pulling the wrapping text around the reduced-size rectangle, over parts of the floated element.
The inset()
function takes up to four side offset values, plus an optional round
keyword, followed by a border-radius
value. The below CSS creates a rectangular shape inset from the reference box of the floated element 20 pixels from the top and bottom and 10 pixels from the left and right, with a border-radius
value of 10 pixels.
.shape {
float: left;
shape-outside: inset(20px 10px 20px 10px round 10px);
}
The offset values use the same rules as the margin
shorthand. Four space-separated values define the top, right, bottom, and left offsets — in that order. You can also set more than one offset at once:
- If there is only one value, it applies to all sides.
- If there are two values, the top and bottom offsets are set to the first value and the right and left offsets are set to the second.
- If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third.
The above rules can therefore also be written as:
.shape {
float: left;
shape-outside: inset(20px 10px round 10px);
}
In the example below we have an inset()
shape used to pull content over the floated element. Change the offset values to see how the shape changes.
You can also add a box value as an alternative reference box. In the example below, try changing the reference box from margin-box
to border-box
, padding-box
, or content-box
to see how the reference box used as the starting point changes before offsets are calculated.
You can also create rectangles based on distances from the top and left edges of the reference box with the rect()
function, or by width and height with the xywh()
function; both of these also support optional rounded corners.