Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

rect(): rectangular clipping, modern and legacy forms

Distinguish the basic shape used by clip-path from the older comma-separated clip rectangle.

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

Syntax

clip-path: rect(10px 80px 60px 20px round 4px);

The modern rect(top right bottom left round …) basic shape defines a rectangle from edge coordinates. Top and bottom are measured from the reference box’s top edge; left and right from its left edge. These are not four inward distances as in inset(). The values are space-separated lengths, percentages or auto, and an optional round clause adds corner radii.

For modern rect(), auto means 0% for top and left, and 100% for right and bottom. If the edges cross, the affected dimension is reduced to zero rather than producing a reversed rectangle. Do not confuse this syntax with the legacy clip: rect(top, right, bottom, left), which uses lengths or auto, has no percentage or rounded-corner form, and applies to absolutely positioned elements. The clip property is deprecated; that does not make modern rect() in clip-path deprecated.

The example clips a 100×80 fixed-position box to x = 20–80 and y = 10–60, with 4px rounded corners. Hit testing accepts (30,30) and rejects (85,30) and (30,65). Switching to the legacy rectangle gives the same results at those points. Layout remains 100×80. Syntax checks accept percentages in the modern form but reject commas there and percentages in the legacy form.

Examples

const box=document.createElement('div');box.style.cssText='position:fixed;left:0;top:0;width:100px;height:80px;background:blue;clip-path:rect(10px 80px 60px 20px round 4px)';document.body.append(box);
const hit=(x,y)=>document.elementFromPoint(x,y)===box;
const modern=''+hit(30,30)+','+hit(85,30)+','+hit(30,65);
box.style.clipPath='none';box.style.clip='rect(10px, 80px, 60px, 20px)';
const legacy=''+hit(30,30)+','+hit(85,30)+','+hit(30,65);
console.log('modern='+modern+'; legacy='+legacy+'; layout='+box.offsetWidth+'x'+box.offsetHeight+'; modern-percent='+CSS.supports('clip-path','rect(10% 80% 75% 20%)')+'; modern-comma='+CSS.supports('clip-path','rect(10px,80px,60px,20px)')+'; legacy-percent='+CSS.supports('clip','rect(10%,80%,75%,20%)'));

Result

modern=true,false,false; legacy=true,false,false; layout=100x80; modern-percent=true; modern-comma=false; legacy-percent=false

Verified in Chromium 157.0.8103.51. Modern rect() support must be checked separately from legacy clip. Clipping changes painting and hit testing; it is not a mechanism for protecting hidden content.

Sources