The Box ModelCore· 30 min read

Borders & Rounded Corners

Draw lines around elements and soften them into rounded corners and pills.

What you will learn

  • Set border style, width and colour
  • Use the border shorthand
  • Round corners with border-radius

The border shorthand

A border has three parts: width, style and colour. The shorthand combines them: border: 2px solid #333;.

Border styles and single sides
<style>
  .a { border: 3px solid #4338ca; padding: 10px; margin-bottom: 8px; }
  .b { border: 2px dashed #ef4444; padding: 10px; margin-bottom: 8px; }
  .c { border-bottom: 4px solid #06b6d4; padding: 10px; margin-bottom: 8px; }
</style>
<div class="a">solid border</div>
<div class="b">dashed border</div>
<div class="c">just a bottom border</div>
Live preview

Each box reads the three border parts in the order width, style, colour:

  • .a3px solid #4338ca is a solid 3px indigo line on all four sides.
  • .b2px dashed #ef4444 swaps the style to dashed, giving a broken red outline.
  • .cborder-bottom targets only the bottom side, drawing a single underline-style line. You can border any one side with border-top, border-left and so on.

Rounded corners

border-radius rounds the corners. A large value (or 50%) makes circles and pills.

border-radius: cards, pills, circles
<style>
  .card { border: 1px solid #e6e8f0; border-radius: 14px; padding: 16px; margin-bottom: 8px; }
  .pill { background: #4338ca; color:#fff; padding: 8px 18px; border-radius: 999px; display:inline-block; }
  .circle { width: 60px; height: 60px; background: #06b6d4; border-radius: 50%; }
</style>
<div class="card">A rounded card</div>
<span class="pill">A pill button</span>
<div class="circle"></div>
Live preview

The size of border-radius decides how round things get:

  • .card14px gives gently softened corners, the classic card look.
  • .pill999px is a huge value, so the short ends round completely into a “pill” shape.
  • .circle50% on an equal-sided square rounds every corner until it becomes a perfect circle.

Tip: border-radius: 50% on a square element makes a perfect circle — handy for avatars and profile photos.

Q. What does border-radius: 50% do to a square element?

Answer: border-radius: 50% rounds all corners enough to turn a square into a circle.

✍️ Practice

  1. Make a card with a 1px border and 12px rounded corners.
  2. Turn a square div into a circle with border-radius: 50%.

🏠 Homework

  1. Add borders and rounded corners to the cards on your landing page.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →