Favorites

rect() CSS Function

rect()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The rect() function defines a rectangle by the distances of its edges from the top and left of the element, used by clip-path.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

Sunset
Demo Code
HTML Code
<img class="demo-element" src="/css-properties/images/sunset.jpg" alt="Sunset">
CSS Code
.demo-element {
	width: 260px;
	display: block;
	border-radius: 6px;
	clip-path: rect(0 100% 100% 0);
}

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

<div class="wrap">
<h1>CSS rect() examples</h1>
<div class="grid">
<div class="card">
<div class="frame"><div class="photo"></div></div>
<div class="label">no clip-path</div>
</div>
<div class="card">
<div class="frame"><div class="photo a"></div></div>
<div class="label">rect(10% 90% 80% 20%)</div>
</div>
<div class="card">
<div class="frame"><div class="photo b"></div></div>
<div class="label">rect(15% 85% 85% 15% round 20px)</div>
</div>
<div class="card">
<div class="frame"><div class="photo c"></div></div>
<div class="label">hover: rect(0 0 100% 0) to rect(0 100% 100% 0)</div>
</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* rect() examples */
.photo {
height: 160px;
border-radius: 6px;
background:
radial-gradient(circle at 30% 30%, #fde047 0 18%, transparent 19%),
linear-gradient(160deg, #38bdf8 0 55%, #16a34a 55%);
}

.frame {
background: repeating-conic-gradient(#e2e8f0 0 25%, #fff 0 50%) 0 0 / 16px 16px;
border-radius: 6px;
}

.a { clip-path: rect(10% 90% 80% 20%); }
.b { clip-path: rect(15% 85% 85% 15% round 20px); }
.c { clip-path: rect(0 0 100% 0); transition: clip-path 0.6s ease; }
.card:hover .c { clip-path: rect(0 100% 100% 0); }
Open in editor

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.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.