Border Radius — CSS

border-radius rounds the corners of a box: one value for all four corners, or four values read clockwise from the top left. border-radius: 50% turns a square…

Look at the buttons in the apps you use every day. Almost none of them have sharp corners. Profile photos on WhatsApp are even fully round. The buttons and the photos are made with the same property: border-radius, which rounds the corners of a box.

The value sets how big the curve in each corner is: 0 is sharp, 12px is slightly round, and 50% on a square makes a circle. The box doesn't need a border: its background colour is cut along the curve too.

Rounding the corners

This example makes an orange box with rounded corners:

<div class="box"></div>

<style>
.box {
  width: 160px;
  height: 160px;
  background-color: orange;
  border-radius: 12px;
}
</style>

The result: an orange box with slightly rounded corners. One value applies to all four corners. The value needs a unit: 12px or 50%, not 12 or 50.

50%: circle or ellipse

border-radius: 50% on a square makes a perfect circle. The percentage is calculated from the box's own size. On a 160px box, 50% is 80px, half the length of a side. So the curve of each corner runs to the middle of the side and joins the curve of the next corner.

On a box that isn't square, 50% doesn't make a circle. The percentage is calculated separately for two directions: horizontally from the box's width, vertically from the box's height. On a 200 × 100px box, the curve is 100px wide and 50px tall, so the result is an ellipse (an oval). If you need a circle, make width and height the same first. If you need a pill shape (fully round left and right ends), use a big px number, like border-radius: 999px.

Why write a circle as 50% and not 80px? Because 50% still makes a circle when the box's size changes. 80px only fits a 160px box: make the box bigger, and the result is no longer a circle.

Different corners

Each corner has a property of its own. This rule rounds only the top left corner:

.box {
  border-top-left-radius: 10px;
}

The other three properties: border-top-right-radius, border-bottom-right-radius and border-bottom-left-radius. border-radius can also take four values on one line. The four values are read clockwise from the top left: top left, top right, bottom right, bottom left. For example, a chat bubble with a sharp bottom left corner:

.chat {
  border-radius: 16px 16px 16px 0;
}

⚠️ Why are the corners still sharp?

TL;DR: border-radius rounds the corners of a box: one value for all four corners, or four values read clockwise from the top left. border-radius: 50% turns a square into a circle. On a box that isn't square the result is an ellipse (an oval), because the percentage is calculated separately from the width and from the height. For only one corner, use that corner's property, like border-top-left-radius for the top left.

⚡ Curved corners

Write:

.box {
  width: 160px;
  height: 160px;
  background-color: orange;
  border-radius: 12px;
}

Meaning: border-radius rounds all four corners of the box. The bigger the number, the rounder the corners. The value needs a unit: 12px, not 12.

⚡ Circle or ellipse

Guess first: does border-radius: 50% on a 200 × 100px box make a circle?

No, the result is an ellipse (an oval). The percentage is calculated separately: the curve is 100px wide (50% of the 200px width) and 50px tall (50% of the 100px height).

Meaning: 50% only makes a circle on a square. For a circle, make width and height the same first. For a pill shape (fully round left and right ends), use a big px number, like 999px.

⚡ Different corners

Write:

.chat {
  border-radius: 16px 16px 16px 0;
}

Meaning: Four values are read clockwise from the top left: top left, top right, bottom right, bottom left. The fourth value in this example is 0, so the bottom left corner stays sharp, like a chat bubble.

What you will learn