πŸ“ CSS Tutorial: border-width

πŸ“Œ Introduction

The border-width property in CSS controls the thickness of an element’s border. It is part of the CSS border system, which includes border-style andborder-color. You can apply border-width to all sides at once or to individual sides for fully customized borders. Understanding border-width helps you design clean, structured, and visually balanced UI components. ✨

🎯 Why Use border-width?

  • To control the thickness of borders 🧱
  • To create emphasis with thicker edges 🎨
  • To build tables, cards, boxes, and outlines ✏️
  • To design unique shapes with different widths per side πŸ”²

✨ Syntax

Basic Syntax

selector {
  border-width: <length> | thin | medium | thick;
}

Note

The values thin, medium, and thick are predefined by browsers β€” exact pixel values vary slightly across devices.

🧩 Ways to Use border-width

1. Single Value (All Sides)

Single Value

.box {
  border-width: 4px;
}

2. Two Values

First applies to top & bottom, second to left & right.

Two Values

.box {
  border-width: 5px 10px;
}

3. Three Values

Applies to: top | left+right | bottom

Three Values

.box {
  border-width: 5px 10px 15px;
}

4. Four Values (Each Side)

Four Values

/* top | right | bottom | left */
.box {
  border-width: 3px 6px 9px 12px;
}

🧩 Per-Side Border Width Properties

Individual Sides

.box {
  border-top-width: 4px;
  border-right-width: 6px;
  border-bottom-width: 8px;
  border-left-width: 10px;
}

πŸ“ Using border-width with border-style

Borders require a style to become visible. Without border-style, border-width has no visual effect.

Visible Border Example

.box {
  border-style: solid;
  border-width: 5px;
}

πŸ”’ Predefined Keyword Values

KeywordApprox SizeUsage
thin~1pxLight outlines or separators
medium~3px (default)Standard border thickness
thick~5px+Emphasis and bold borders

πŸ”₯ Practical Examples

1. Card with Slim Border

Slim Border Card

.card {
  border: solid 1px #ccc;
  padding: 20px;
}

2. Button with Bold Border

Bold Button

button {
  border-width: 4px;
  border-style: solid;
  border-color: #007bff;
}

3. Border with Different Thickness per Side

Creative Border

.creative-box {
  border-style: solid;
  border-width: 2px 4px 6px 8px;
}

4. Responsive Border

Percentage Border

.responsive {
  border-width: 1%;
  border-style: solid;
}

πŸ–ΌοΈ Visual Demo

>>β€œBorders frame your content β€” choose the width carefully to balance clarity and aesthetics.” ✨

πŸŽ‰ Conclusion

The border-width property gives you fine control over the thickness of element borders. Whether you want thin separators, bold outlines, or creative asymmetrical borders, this property helps you design visually appealing and structured UI components. Combine border-width with border-style and border-color for complete border customization. πŸš€