π Introduction
The border-radius property in CSS allows you to create rounded corners on elements. It works on all elements with a visible rectangular box β including divs, buttons, images, inputs, and more. With border-radius, you can design smooth UI components, circles, pills, cards, and modern layouts. β¨
π― Why Use border-radius?
- Smooth modern UI design π
- Create circles and oval shapes π΅
- Soft corner buttons and cards π¦
- Improve readability and visual comfort π
β¨ Syntax
Basic Syntax
selector {
border-radius: <length> | <percentage>;
}Note
50% to create perfect circles.π§© Ways to Use border-radius
1. Single Value (All Corners)
All Corners
.box {
border-radius: 15px;
}2. Two Values (Opposite Corners)
Applies first value to top-left & bottom-right, second value to top-right & bottom-left.
Two Values
.box {
border-radius: 20px 40px;
}3. Four Values (Each Corner)
Four Corners
/* TL | TR | BR | BL */
.box {
border-radius: 10px 20px 30px 40px;
}4. Slash Syntax (Elliptical Corners)
The slash / divides horizontal and vertical radii.border-radius: [horizontal-radii] / [vertical-radii];
Elliptical Radius
.box {
border-radius: 40px / 10px;
}5. Per-Corner Properties
Individual Corners
.box {
border-top-left-radius: 20px;
border-top-right-radius: 5px;
border-bottom-right-radius: 25px;
border-bottom-left-radius: 10px;
}π’ Creating Shapes With border-radius
1. Perfect Circle
Circle
.circle {
width: 150px;
height: 150px;
background: #4da3ff;
border-radius: 50%;
}2. Pill (Rounded Button)
Pill Shape
.pill {
padding: 12px 30px;
border-radius: 9999px;
}3. Oval
Oval
.oval {
width: 200px;
height: 100px;
background: #ffadad;
border-radius: 50%;
}4. Speech Bubble
Speech Bubble
.bubble {
border-radius: 20px;
position: relative;
}
.bubble::after {
content: "";
position: absolute;
bottom: -10px;
left: 20px;
border-width: 10px;
border-style: solid;
border-color: #ddd transparent transparent transparent;
}π Summary Table
| Format | Usage |
|---|---|
| border-radius: 20px; | Same radius on all corners |
| border-radius: 20px 40px; | Opposite corners |
| border-radius: 10px 20px 30px 40px; | Each corner individually |
| border-radius: 40px / 10px; | Elliptical corners |
| border-top-left-radius: 30px; | Specific corner control |
πΌοΈ Visual Demo
Further details can be found at: https://dummyimage.com/900x260/eeeeee/000000&text=border-radius+demo
π Conclusion
The border-radius property is one of the simplest but most powerful CSS tools. From soft corner cards to circles and pills, it helps you design smooth, modern interfaces. Master radius combinations and elliptical values to unlock advanced design patterns. π