Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

inset(): a rectangular basic shape

Define an inset rectangle with optional rounded corners for clipping or float exclusion.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

clip-path: inset(10px 20px round 4px);

inset() defines a basic shape by measuring inward from a reference box. One to four offsets follow the familiar top, right, bottom, left expansion used by margin. The optional round clause gives corner radii. Percentages depend on the corresponding reference-box dimension; if opposing offsets exceed that dimension, the specification reduces them proportionally instead of creating a negative rectangle.

The consuming property determines the effect. In clip-path, the shape clips painting and affects hit testing outside the visible region, but does not shrink the element's layout box. In shape-outside, the same kind of shape controls how inline content wraps around a float. It does not automatically perform the visual clipping done by clip-path.

The example clips a 100 by 80 pixel element with inset(10px 20px round 4px). Hit testing finds the element at an interior point but not at a point in the clipped strip. Its measured layout remains 100 by 80 pixels. Those measurements distinguish a clipping operation from changing width, height, padding or the surrounding document flow.

Examples

const element=document.createElement('div');element.id='clip-example';
element.style.cssText='position:fixed;left:0;top:0;width:100px;height:80px;background:blue;clip-path:inset(10px 20px round 4px)';
document.body.append(element);
const hit=(x,y)=>document.elementFromPoint(x,y)===element;
console.log('inside='+hit(50,40)+'; clipped='+hit(5,40)+'; layout='+element.getBoundingClientRect().width+'x'+element.getBoundingClientRect().height+'; clip='+getComputedStyle(element).clipPath);

Result

inside=true; clipped=false; layout=100x80; clip=inset(10px 20px round 4px)

The inside result is true and the clipped-point result is false, while the box keeps its original dimensions.

Sources