Special Offer Diwali Special Bundle Offer: 3 courses for ₹8,999, save ₹9,001 (50% OFF)! Limited seats available. View Bundles →
0% Completed
Tutorials / CSS Tutorial / Chapter 3: The Box Model & Sizing
CSS ⏱ 10 min read

Borders, Outlines, and Border Radius

Borders frame components, separate content sections, and create friendly rounded corners.

What is it?

The `border` property draws lines around element padding, while `border-radius` rounds the corners. `outline` draws a line outside the border without occupying layout space.

Why is it used?

Borders give components distinct edges, rounded buttons look modern and touchable, and outlines provide essential accessibility focus rings.

Detailed Explanation

Border Properties: • `border`: Shorthand for `border-width border-style border-color` (e.g. `1px solid #eceae4`). • Individual sides: `border-top`, `border-bottom`, etc. • `border-radius`: Values like `6px` round slightly, `50%` creates circles, and `9999px` creates pill shapes. • `outline`: Unlike borders, outlines do not affect element dimensions or push other elements away. Always preserve custom outline rings for keyboard accessibility (`:focus-visible`).

Syntax Structure

Syntax Blueprint
border: 1px solid #eceae4;
border-radius: 8px;
outline: 2px solid #1c1c1c;
outline-offset: 2px;

Code Example

CSS Code
/* Modern Pill Button */
.btn-pill {
  background-color: #1c1c1c;
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: 9999px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Accessible Focus Outline */
.btn-pill:focus-visible {
  outline: 2px solid #1c1c1c;
  outline-offset: 3px;
}

/* Circular Avatar */
.avatar-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #eceae4;
  object-fit: cover;
}

Explanation of the Code

• `border-radius: 9999px` renders a perfect pill badge regardless of content length. • `outline-offset: 3px` creates an elegant ring with white gap around focused buttons for keyboard navigation.

Expected Output

A pill-shaped dark button that exhibits an accessible focus ring when tabbed with keyboard, alongside a circular avatar.

Real-World Application

Modern design systems use subtle borders (`#eceae4` or `rgba(0,0,0,0.08)`) to structure clean minimalist cards without heavy drop-shadows.

Common Mistakes to Avoid

• Setting `outline: none` without providing an alternative focus state (ruining accessibility for keyboard users). • Using `border-radius: 50%` on non-square elements (creates an oval rather than a circle).

Quick Practice Challenge

Create a circular user profile badge with 64px width and height, 50% border radius, and a 2px subtle border.

Key Takeaways

• Shorthand: `border: width style color;`. • Use `border-radius: 50%` for circles and `9999px` for pill buttons. • Always maintain visible focus rings (`:focus-visible`) with `outline`.