π Introduction
The border-style property in CSS defines the pattern or style of an elementβs border. It determines how the border line looks β solid, dashed, dotted, double, and more. This property is essential because without a border style, you cannot see borders even ifborder-width and border-color are set. β¨
π― Why Use border-style?
- To visually define boundaries between elements π¦
- To create distinct UI styles (dashed, dotted, double) π¨
- To improve readability and structure of layouts π
- To fully customize borders of cards, buttons, tables, and inputs π§©
β¨ Syntax
Syntax
selector {
border-style: none | solid | dashed | dotted | double | groove | ridge | inset | outset;
}Note
π§© Available Border Styles
1. none
No border is drawn.
2. solid
A single continuous line β most common.
3. dashed
A border made of dashes β great for notes or highlights.
4. dotted
A border with round dots β subtle and decorative.
5. double
A two-line border with space between β elegant for emphasis.
6. groove / ridge
3D-looking borders based on border color.
7. inset / outset
3D styles that make elements appear pressed in or popped out.
π Example for All Styles
All Styles Overview
.none { border-style: none; }
.solid { border-style: solid; }
.dashed { border-style: dashed; }
.dotted { border-style: dotted; }
.double { border-style: double; }
.groove { border-style: groove; }
.ridge { border-style: ridge; }
.inset { border-style: inset; }
.outset { border-style: outset; }π§© Setting Styles Per Side
You can specify up to four border styles in clockwise direction:
Per-Side Styles
/* top | right | bottom | left */
.box {
border-style: solid dashed dotted double;
}π₯ Practical Examples
1. Card With Solid Border
Solid Card
.card {
border: 2px solid #333;
padding: 20px;
}2. Dotted Divider
Dotted Divider
.divider {
border-bottom: 2px dotted #666;
}3. Dashed Button Outline
Dashed Button
button {
border: 2px dashed #007bff;
background: transparent;
}4. 3D Effect Box
3D Border
.threeD {
border-style: groove;
border-width: 5px;
border-color: #888;
}π Comparison Table
| Style | Appearance | Use Case |
|---|---|---|
| solid | Single straight line | General UI elements |
| dashed | Broken dash line | Highlight or emphasize |
| dotted | Round dots | Soft decorative borders |
| double | Two parallel lines | Elegant highlight sections |
| groove/ridge | 3D effect variations | Panels, frames |
| inset/outset | Pressed or raised effect | Buttons, containers |
πΌοΈ Visual Demo
Further details can be found at: https://dummyimage.com/900x260/eeeeee/000000&text=border-style+demo
π Conclusion
The border-style property gives you control over the look and feel of element borders. Whether you're building clean UI elements, decorative layouts, or stylish components, choosing the right style adds clarity and visual appeal. Combine border-style with border-width andborder-color for complete border customization. π