Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 139 ยท The Box Model

Rounded Corners

Round corners with CSS border-radius. Learn single and per-corner values, elliptical corners with the slash syntax, percentages, circles, pills and blob shapes.

Sharp corners feel technical and strict; rounded corners feel friendly and touchable. Almost every modern interface rounds something, from buttons and cards to avatars and chat bubbles. In CSS, all of that comes from one property: border-radius.

Despite its name, border-radius does not need a border. It rounds the element's whole box: the background, the border, the shadow and the outline all follow the curve. This lesson covers the basic values, rounding single corners, elliptical corners, and the classic shapes you can build: circles, pills and organic blobs.

Rounding all four corners

Give border-radius one length and every corner gets a quarter-circle of that radius:

CSS
.card {
  border-radius: 12px;
}

Small radii (4โ€“8px) give a subtle softening, typical for inputs and buttons. Medium radii (12โ€“20px) suit cards and dialogs. Larger values start to change the character of the shape completely.

Radius sizes

Look at the last two boxes. The box is 80px tall (plus its border), so a radius bigger than half that height cannot fit. When the corners would overlap, the browser scales all the radii down proportionally until they fit. That is why 999px produces perfectly round ends instead of something strange, and it is the secret behind pill shapes.

Rounding individual corners

The shorthand takes one to four values, starting at the top-left corner and going clockwise:

CSS
.a { border-radius: 16px; }                 /* all corners */
.b { border-radius: 16px 4px; }             /* top-left + bottom-right, then top-right + bottom-left */
.c { border-radius: 16px 4px 0; }           /* top-left, top-right + bottom-left, bottom-right */
.d { border-radius: 16px 16px 0 0; }        /* top-left, top-right, bottom-right, bottom-left */

Notice that this order starts at a corner, not a side, so the two-value form pairs diagonally opposite corners. That catches people out.

Each corner also has its own property, named after both of its edges:

CSS
.tab {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

There are logical versions too, like border-start-start-radius (block start + inline start, the top-left corner in English) and border-end-end-radius. They flip correctly in right-to-left text; more on that in Writing Modes and Logical Properties.

Chat bubbles with per-corner radii

One small corner points each bubble at its sender. Try making it 0, or round a different corner.

Percentages, circles and pills

A percentage radius is measured against the element's own size: horizontal radii use the width, vertical radii use the height. So border-radius: 50% makes each corner's curve reach the middle of each side.

  • On a square, 50% gives a circle.
  • On a rectangle, 50% gives an ellipse, because the horizontal and vertical radii differ.

For a pill (a rectangle with fully round ends), you don't want an ellipse. Use a very large length instead, like 999px or 100vmax; the browser scales it down so the ends become perfect half-circles.

Circle, ellipse and pill

Round avatars. For a circular profile photo, give the image equal width and height (or aspect-ratio: 1), border-radius: 50% and object-fit: cover so the photo isn't squashed. You will learn object-fit in Sizing Images: object-fit and aspect-ratio.

Elliptical corners: the slash syntax

So far each corner has been a quarter-circle. You can also give a corner two radii: one horizontal, one vertical. That makes an elliptical curve. In the shorthand, separate the horizontal values from the vertical values with a slash:

CSS
.leaf {
  /* horizontal radii / vertical radii */
  border-radius: 40px / 20px;
}

Each side of the slash can take one to four values, following the same corner order. For a single corner, the long-hand property takes the two radii separated by a space, without a slash:

CSS
.corner {
  border-top-left-radius: 60px 20px; /* horizontal, vertical */
}

Mixing different percentages on both sides of the slash creates soft, organic blob shapes, a popular decoration behind illustrations and avatars:

Blob shapes

Change the percentages to reshape the blobs. Animating between two such values with a transition or keyframe animation makes a gently "breathing" shape.

How the content and border behave

A few details explain most surprises with rounded corners:

  • The background and border follow the curve. So does box-shadow and, in all current browsers, outline.
  • The inner curve is smaller. The border-radius applies to the outer edge of the border. The padding edge inside it curves with the radius minus the border width, so a thick border gets a tighter curve on the inside.
  • Children are not clipped. If an image or colored child sits right in the corner, it pokes out past the curve. Add overflow: hidden (or overflow: clip) to the rounded parent to clip its content. See Overflow.
  • Nested rounded boxes. When a rounded box sits inside another with some padding, the inner radius should be smaller: roughly the outer radius minus the padding. Equal radii make the gap look uneven at the corners.
CSS
.outer {
  border-radius: 20px;
  padding: 8px;
}
.inner {
  border-radius: 12px; /* 20px - 8px */
}

Picking radii for a whole site

Like shadows and spacing, corner radii look best when they come from a small, consistent set instead of random values on every component. A typical scale has three or four steps, stored as custom properties:

CSS
:root {
  --radius-sm: 4px;    /* inputs, tags, small buttons */
  --radius-md: 10px;   /* cards, dropdowns */
  --radius-lg: 20px;   /* dialogs, large panels */
  --radius-full: 999px; /* pills and round icons */
}

Larger elements generally get larger radii, so the curve looks proportional to the box. The radius also sets the mood of a brand: tight corners feel precise and serious, generous ones feel playful and soft. Whatever you choose, apply it consistently and your interface will feel like one family of shapes.

A newer property, corner-shape, lets you turn rounded corners into bevels, notches or "squircles". At the time of writing it has shipped only in Chromium-based browsers, so treat it as a progressive enhancement on top of a normal border-radius.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which corners get 20px in border-radius: 20px 5px?

    Two values pair diagonally opposite corners: the first value is for top-left and bottom-right, the second for top-right and bottom-left.
  2. 2. What shape does border-radius: 50% give a 200px ร— 100px box?

    Percentages use the width for horizontal radii and the height for vertical radii, so each corner curve is 100px wide and 50px tall, and together they form an ellipse.
  3. 3. How do you make a button into a pill shape whatever its size?

    A huge length is scaled down until the corners fit, giving perfect half-circle ends. 50% would make an ellipse on a wide button.
  4. 4. A rounded card's image pokes out past its top corners. What fixes it?

    Border-radius rounds the card's own box but does not clip children. Overflow clipping cuts the image to the rounded shape.
  5. 5. What does the slash do in border-radius: 40px / 20px?

    Values before the slash are horizontal radii; values after it are vertical radii.

Summary

  • border-radius rounds an element's box, including its background, border, shadow and outline; it doesn't need a border.
  • One to four values go clockwise from the top-left corner; each corner also has its own property, plus logical versions.
  • When radii are too big to fit, the browser scales them down, which is why 999px makes pills.
  • 50% makes a circle on a square and an ellipse on a rectangle.
  • A slash separates horizontal and vertical radii for elliptical corners and blob shapes.
  • Rounded parents don't clip their children; add overflow: hidden or clip, and use smaller radii on nested boxes.

Next: Border Images.