π 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
π§© 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
| Keyword | Approx Size | Usage |
|---|---|---|
| thin | ~1px | Light 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
Further details can be found at: https://dummyimage.com/900x260/eeeeee/000000&text=border-width+demo
π 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. π