The Box Model›Core· 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;.
<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:
.a—3px solid #4338cais a solid 3px indigo line on all four sides..b—2px dashed #ef4444swaps the style todashed, giving a broken red outline..c—border-bottomtargets only the bottom side, drawing a single underline-style line. You can border any one side withborder-top,border-leftand so on.
Rounded corners
border-radius rounds the corners. A large value (or 50%) makes circles and pills.
<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:
.card—14pxgives gently softened corners, the classic card look..pill—999pxis a huge value, so the short ends round completely into a “pill” shape..circle—50%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
- Make a card with a 1px border and 12px rounded corners.
- Turn a square div into a circle with
border-radius: 50%.
🏠 Homework
- Add borders and rounded corners to the cards on your landing page.