Favorites

xywh() CSS Function

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

The xywh() function defines a rectangle by the x and y position of its top-left corner and its width and height, 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 xywh() CSS function defines a rectangle by its position and size: the x and y coordinates of its top-left corner, followed by its width and height. It is a <basic-shape> used with clip-path, offset-path and shape-outside. Many people find it more natural than inset() or rect() because it matches how rectangles are described in design tools and in the SVG rect element.

The x and y values are measured from the top-left corner of the reference box, and can be lengths or percentages. The width and height must not be negative. Because the size is given directly, moving the rectangle only requires changing x and y, which makes xywh() convenient for animating a "window" that slides across an element. An optional round keyword followed by border-radius values rounds the corners.

/* A 200 x 120 window, 20px from the top-left corner */
.thumb {
  clip-path: xywh(20px 20px 200px 120px);
}

/* Centered half-size rectangle with rounded corners */
.focus {
  clip-path: xywh(25% 25% 50% 50% round 16px);
}

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: xywh(0 0 100% 100%);
}

Syntax

xywh() = xywh( <length-percentage>{2} <length-percentage [0,∞]>{2} [ round <'border-radius'> ]? )

Values

  • xThe horizontal distance of the rectangle's left edge from the left of the reference box, as a <length-percentage>.
  • yThe vertical distance of the rectangle's top edge from the top of the reference box, as a <length-percentage>.
  • widthThe width of the rectangle, as a non-negative <length-percentage>.
  • heightThe height of the rectangle, as a non-negative <length-percentage>.
  • round <'border-radius'>Optional. Rounds the corners of the rectangle using border-radius syntax.

Example

<div class="wrap">
<h1>CSS xywh() examples</h1>
<div class="grid">
<div class="card">
<div class="frame"><div class="photo a"></div></div>
<div class="label">xywh(10% 10% 60% 50%)</div>
</div>
<div class="card">
<div class="frame"><div class="photo b"></div></div>
<div class="label">xywh(25% 25% 50% 50% round 16px)</div>
</div>
<div class="card">
<div class="frame"><div class="photo c"></div></div>
<div class="label">animating x from 0% to 60%</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;
}

/* xywh() 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: xywh(10% 10% 60% 50%); }
.b { clip-path: xywh(25% 25% 50% 50% round 16px); }
.c { animation: pan 3s ease-in-out infinite alternate; }

@keyframes pan {
from { clip-path: xywh(0% 20% 40% 60% round 12px); }
to { clip-path: xywh(60% 20% 40% 60% round 12px); }
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS xywh() 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.