rect() CSS Function
The rect() function defines a rectangle by the distances of its edges from the top and left of the element, used by clip-path.
Description
The rect() CSS function defines a rectangle by giving the distances of its four edges from the top and left edges of the reference box. It is a <basic-shape>, used mainly with clip-path to show only a rectangular part of an element, and with offset-path and shape-outside.
The four values are, in order, the top edge, the right edge, the bottom edge and the left edge. This is different from inset(): in rect(), the right and bottom values are measured from the left and top of the box respectively, not from the right and bottom. So rect(10% 90% 80% 20%) describes a rectangle from 10% to 80% vertically and from 20% to 90% horizontally. Each value can be a length, a percentage, or auto, which places that edge on the matching edge of the reference box. An optional round keyword followed by border-radius values rounds the corners.
/* Show the middle part of an image with rounded corners */
.crop {
clip-path: rect(15% 85% 85% 15% round 12px);
}
/* Reveal animation from left to right */
.reveal {
clip-path: rect(0 0 100% 0);
transition: clip-path 0.6s ease;
}
.reveal:hover {
clip-path: rect(0 100% 100% 0);
}
Interactive Demo

Syntax
rect() = rect( [ <length-percentage> | auto ]{4} [ round <'border-radius'> ]? )Values
- topDistance of the top edge from the top of the reference box, as a <length-percentage> or auto (0%).
- rightDistance of the right edge from the left of the reference box, as a <length-percentage> or auto (100%).
- bottomDistance of the bottom edge from the top of the reference box, as a <length-percentage> or auto (100%).
- leftDistance of the left edge from the left of the reference box, as a <length-percentage> or auto (0%).
- round <'border-radius'>Optional. Rounds the corners of the rectangle using border-radius syntax.
Example
Browser Support
The following information will show you the current browser support for the CSS rect() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





