inset() CSS Function
Description
The inset() CSS function is used to define rectangular shapes by specifying the distances from the edges of a box: top, right, bottom, and left. It essentially acts as a shorthand for setting multiple top, right, bottom, and left values at once. This makes it particularly useful in positioning contexts, for example, with absolutely or relatively positioned elements, or when clipping elements using clip-path.
The values in inset() can be expressed using lengths (like px, em), percentages (%), or the keyword auto. If fewer than four values are provided, the function applies the same rules as the shorthand for margin or padding: one value applies to all sides, two values apply to top/bottom and left/right, and three values apply to top, left/right, and bottom.
An optional fourth parameter, known as the “round” value, allows you to add border-radius-like rounding to the corners of the defined inset rectangle. This can be useful for creating smooth clipped shapes or decorative effects.
For example, using inset() with div elements can simplify complex positioning:
div.box {
position: absolute;
inset: 10px 20px 30px 40px; /* top, right, bottom, left */
background-color: lightblue;
}
You can also combine it with clip-path to create interesting masking effects:
div.clip {
clip-path: inset(10% 5% 10% 5% round 15px);
}
Here, the element is clipped 10% from the top and bottom, 5% from the sides, and corners are rounded by 15px.
Overall, inset() provides a concise, readable, and flexible way to define rectangular offsets, replacing the need for multiple individual property declarations.
Syntax
inset() = inset( [offset]{1,4} [round <border-radius>]? )
Values
- offsetWhen all of the first four arguments are supplied they represent the top, right, bottom and left offsets from the reference box inward that define the positions of the edges of the inset rectangle. These arguments follow the syntax of the margin shorthand, that let you set all four insets with one, two or four values.
- border-radiusdefine rounded corners for the inset rectangle using the border-radius shorthand syntax
Example
Browser Support
The following information will show you the current browser support for the CSS inset() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
This function is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
