CSS border-radius: rounded corners, circles, and ellipses
CSS border-radius rounds an element’s border and background corners. A single value such as 20px applies to all four corners. 50% makes a circle when the outer box is square and an ellipse when it is rectangular.
Assign radii to all four corners
| Number of values | Corners affected |
|---|---|
1 · 20px |
All four corners |
2 · 10px 30px |
Top left and bottom right / top right and bottom left |
3 · 10px 30px 50px |
Top left / top right and bottom left / bottom right |
4 · 10px 30px 50px 0 |
Top left → top right → bottom right → bottom left |
Four values start at the top-left corner and go clockwise. For different horizontal and vertical radii, put the horizontal values before the slash and the vertical values after it. In the following rule, the top-left radius is 20px horizontally and 80px vertically. Each group follows the shorthand rules in the table. Negative values are invalid, and 0 leaves a square corner. See CSS Backgrounds and Borders · Border Radius.
.box {
border-radius: 20px 40px 60px 80px / 80px 60px 40px 20px;
}
Compare rounded rectangles, a circle, and an ellipse
Save the code as radius.html and open it. The four shapes share the same background and border, and no other files are required.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare corner radii</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; }
.samples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px 12px; max-width: 520px; }
figure { margin: 0; }
figcaption { margin-bottom: 8px; font-size: 14px; }
.shape { width: 140px; height: 100px; max-width: 100%;
border: 3px solid #17516b; background: #77c9cb; }
.rounded { border-radius: 20px; }
.corners { border-radius: 10px 30px 50px 0; }
.circle { width: 100px; height: auto; aspect-ratio: 1; border-radius: 50%; }
.ellipse { border-radius: 50%; }
</style>
</head>
<body>
<h1>Compare border-radius shapes</h1>
<div class="samples">
<figure><figcaption>Same 20px radius</figcaption><div class="shape rounded"></div></figure>
<figure><figcaption>Four different corners</figcaption><div class="shape corners"></div></figure>
<figure><figcaption>Square + 50% = circle</figcaption><div class="shape circle"></div></figure>
<figure><figcaption>Rectangle + 50% = ellipse</figcaption><div class="shape ellipse"></div></figure>
</div>
</body>
</html>
The first shape uses 20px on every corner. The second keeps its bottom-left corner square with 0. The last two use 50%. With enough room, the circle measures 100×100px and the ellipse 140×100px. The dimensions include the borders because the example uses box-sizing: border-box.
Change the first shape from 20px to 40px to see the corners round further, then restore the original. On the third shape, change only aspect-ratio: 1 to aspect-ratio: 7 / 5. Its height becomes smaller than its width, so the same 50% produces an ellipse. Restore 1 to get the circle back.
Work with percentages and single corners
A horizontal percentage uses the border box width and a vertical percentage uses its height. If adjacent radii cannot fit along an edge, all radii scale down by the same factor. For example, 80px on a 140×100px box asks for 160px along each vertical edge. The browser scales each radius to 50px. See CSS Backgrounds and Borders · Overlapping Curves.
To override one corner, put its longhand after the shorthand. The rule below sets the top-left radius to 40px horizontally and 10px vertically. A longhand uses a space between its two values. A single value applies along both axes.
.box {
border-radius: 20px;
border-top-left-radius: 40px 10px;
}
Round card images and table edges
A rounded parent may still show a square image spilling over its corners. To clip only the picture, round the image directly or apply clipping to a wrapper used just for the image. This example applies clipping to the card. See CSS Backgrounds and Borders · Corner Clipping for how the clip follows the curve.
.card {
border-radius: 20px;
overflow: hidden;
}
.card img {
display: block;
max-width: 100%;
height: auto;
}
If the card contains menus or links, check whether overflow: hidden clips an open menu or a focus outline. For a rounded outline around a table using border-collapse: collapse, try setting the radius and clipping on a separate wrapper.




