TExcelTAD
Home › CSS › CSS Rounded Corners

CSS Rounded Corners

Square boxes can look harsh. The border-radius property rounds an element's corners, so you can make soft cards, pill-shaped buttons, circular avatars and even organic blob shapes. The rounding also clips the background, and the border, outline and box shadow all follow it.

The basics

border-radius takes a length or a percentage. The value is the radius of the circle (or ellipse) used to draw each corner.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: system-ui, sans-serif; display: flex; flex-wrap: wrap; gap: 14px; padding: 10px; }
  .box { width: 110px; height: 80px; background: #5c6bc0; color: white; display: grid; place-items: center; }
  .r0 { border-radius: 0; }
  .r8 { border-radius: 8px; }
  .r25 { border-radius: 25px; }
  .pill { border-radius: 999px; }
  .circle { width: 80px; border-radius: 50%; background: #ef6c00; }
  .border { border-radius: 16px; border: 4px dashed #2e7d32; background: #e8f5e9; color: #2e7d32; }
</style>
</head>
<body>
  <div class="box r0">0</div>
  <div class="box r8">8px</div>
  <div class="box r25">25px</div>
  <div class="box pill">999px</div>
  <div class="box circle">50%</div>
  <div class="box border">border</div>
</body>
</html>

Tip: For a pill shape, use a very large value such as 999px instead of 50%. A percentage gives an ellipse on a non-square box, but a huge pixel value is capped at half the shorter side, which gives perfect semicircular ends.

Corner by corner

Like margin and padding, the shorthand takes one to four values. The order goes clockwise from the top-left corner.

Shorthand Meaning
border-radius: 20px; all four corners
border-radius: 20px 0; top-left & bottom-right 20px, top-right & bottom-left 0
border-radius: 20px 5px 40px; top-left 20px, top-right & bottom-left 5px, bottom-right 40px
border-radius: 1px 2px 3px 4px; top-left, top-right, bottom-right, bottom-left

Each corner also has its own property: border-top-left-radius, border-top-right-radius, border-bottom-right-radius and border-bottom-left-radius.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: system-ui, sans-serif; display: flex; flex-wrap: wrap; gap: 14px; padding: 10px; }
  div { width: 120px; height: 90px; background: #26a69a; color: white; display: grid; place-items: center; font-size: 13px; text-align: center; }
  .a { border-radius: 30px 0; }
  .b { border-radius: 40px 40px 0 0; }
  .c { border-radius: 0 0 50px 50px; background: #ab47bc; }
  .d { border-top-left-radius: 60px; background: #ef5350; }
  .bubble { border-radius: 20px 20px 20px 0; background: #42a5f5; }
</style>
</head>
<body>
  <div class="a">30px 0</div>
  <div class="b">40 40 0 0 (tab)</div>
  <div class="c">0 0 50 50</div>
  <div class="d">top-left only</div>
  <div class="bubble">chat bubble</div>
</body>
</html>

Elliptical corners

Give a corner two radii separated by a slash, horizontal / vertical, and it becomes a quarter of an ellipse. With all eight values set you can draw egg and blob shapes.

Syntax Meaning
border-radius: 50px / 20px; every corner 50px wide, 20px tall
border-top-left-radius: 60px 30px; one corner, horizontal then vertical, no slash
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; an egg
html · try it yourself
<!DOCTYPE html>
<html>
<head>
<style>
  body { display: flex; gap: 24px; align-items: center; padding: 20px; font-family: system-ui, sans-serif; }
  .ellipse { width: 160px; height: 90px; background: #ffca28; border-radius: 80px / 30px; display: grid; place-items: center; }
  .egg { width: 110px; height: 140px; background: #fff3e0; border: 3px solid #ffb74d;
         border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; }
  .blob { width: 140px; height: 140px; background: linear-gradient(135deg, #f06292, #7e57c2);
          border-radius: 63% 37% 54% 46% / 55% 48% 52% 45%; }
</style>
</head>
<body>
  <div class="ellipse">80px / 30px</div>
  <div class="egg"></div>
  <div class="blob"></div>
</body>
</html>

Practical patterns

Rounded corners clip backgrounds, but not child content. A child that touches the corner (an image at the top of a card, say) still pokes out square. Add overflow: hidden to the parent so everything is clipped to the curve.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: system-ui, sans-serif; display: flex; gap: 20px; padding: 10px; background: #eceff1; }
  .card { width: 170px; background: white; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
  .clip { overflow: hidden; }
  .banner { height: 80px; background: linear-gradient(120deg, #00897b, #43a047); }
  .body { padding: 10px; }
  .avatar { width: 56px; height: 56px; border-radius: 50%; background: #ffb300; border: 4px solid white; margin-top: -38px; }
</style>
</head>
<body>
  <div class="card"><div class="banner"></div><div class="body">No overflow: hidden, so the banner corners stay square</div></div>
  <div class="card clip"><div class="banner"></div><div class="body"><div class="avatar"></div>Clipped neatly</div></div>
</body>
</html>

Note: If adjacent radii add up to more than the side length, the browser scales them all down proportionally. That's why 999px still produces a neat pill.

Test yourself

Which value turns a 100×100px square into a circle?

  1. border-radius: 100%
  2. border-radius: 50%
  3. border-radius: circle
  4. border-radius: 25px

With border-radius: 10px 20px 30px 40px;, which corner gets 30px?

  1. top-left
  2. top-right
  3. bottom-right
  4. bottom-left

A card has rounded corners, but the image inside still shows square corners. What fixes it?

  1. border-collapse: collapse
  2. overflow: hidden on the card
  3. z-index: 1
  4. display: block on the image