How to Use Rounded Corners in CSS
Rounded corners in CSS are achieved using the border-radius property. This simple yet powerful feature allows you to soften the edges of elements, creating modern and visually appealing designs.
1. Why Use Rounded Corners in CSS?
- Modern Aesthetics – Rounded elements look cleaner and more user-friendly.
- Highlighting – Buttons, cards, and images stand out with smooth corners.
- Consistency – Adds uniformity across UI components.
- User Experience – Reduces sharp edges, making interfaces feel more inviting.
border-radius in CSS?The
border-radius property controls the curve of element corners. It accepts pixel (px), percentage (%), em, or rem values.Basic Syntax:
selector {
border-radius: value;
}
3. Example of Rounded Corners
div {width: 200px;height: 100px;background-color: steelblue;border-radius: 20px;}<div>Rounded Box</div>
- Effect: The box will have 20px rounded corners.
| Value | Description |
|---|---|
border-radius: 0; | Sharp corners (default). |
border-radius: 10px; | Slightly rounded corners. |
border-radius: 50px; | Very rounded corners. |
border-radius: 50%; | Turns the element into a circle/oval (if square). |
border-radius: 20px 0; | Top-left and bottom-right corners rounded. |
5. Rounding Specific Corners
CSS allows rounding individual corners using the following properties:
border-top-left-radius: 30px;
border-top-right-radius: 15px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 0;
Example:
CSS allows rounding individual corners using the following properties:
border-top-left-radius: 30px;
border-top-right-radius: 15px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 0;
Example:
div {border-top-left-radius: 40px;border-bottom-right-radius: 40px;
}
- Effect: Only the top-left and bottom-right corners are rounded.
6.
You can define multiple corners in one line using shorthand notation.border-radius Shorthand| Shorthand Syntax | Explanation |
|---|---|
border-radius: 30px; | All four corners are rounded by 30px. |
border-radius: 30px 15px; | Top-left/bottom-right = 30px, top-right/bottom-left = 15px. |
border-radius: 30px 20px 10px; | Top-left = 30px, top-right/bottom-left = 20px, bottom-right = 10px. |
border-radius: 30px 10px 20px 5px; | Top-left, top-right, bottom-right, bottom-left. |
7. Rounded Corners for Images
img {width: 300px;height: auto;border-radius: 15px;
}
- Effect: Images with softened edges.
- Tip: Use
border-radius: 50%to create a circular image.
8. Circle and Oval Shapes
- Perfect Circle (Square Elements):
.circle {width: 100px;height: 100px;border-radius: 50%;}
- Oval (Rectangle Elements):
.oval {width: 200px;height: 100px;border-radius: 50%;}
9. Combining Border and Border-Radius
.button {background-color: tomato;color: white;padding: 10px 20px;border: 2px solid red;border-radius: 25px;
}
- Effect: A pill-shaped button with a border.
div {border-radius: 10%;}
- Effect: Rounded corners scale relative to the element size, ensuring responsiveness.
.button {background-color: royalblue;color: white;padding: 12px 24px;border: none;border-radius: 8px;transition: border-radius 0.3s ease;}.button:hover {border-radius: 20px;}
- Effect: The button's corners become more rounded on hover.
.pill {padding: 12px 30px;border-radius: 50px;}
- Effect: Creates pill-shaped buttons for sleek designs.
input {padding: 8px;border: 1px solid #ccc;border-radius: 10px;}
- Effect: Smooth input fields that improve form aesthetics.
14. Best Practices for Rounded Corners
- Keep it Subtle – Avoid excessive rounding unless intentional (circles or pills).
- Consistency – Use uniform
border-radiusfor buttons, images, and cards. - Responsiveness – Use percentage values (
%) for flexible designs. - Hover Effects – Apply dynamic rounding to enhance user interactions.
- Accessibility – Ensure text and content remain readable within rounded elements.
15. Why Use Rounded Corners?
- Aesthetic Appeal – Gives elements a softer, more approachable look.
- Focus – Highlights buttons, forms, and call-to-action elements.
- Modern Design – Aligns with current web design trends.
- User Engagement – Rounded buttons and images improve visual hierarchy and interaction.
Rounded corners in CSS enhance the visual appeal of websites by softening sharp edges and creating modern, engaging designs. With the border-radius property, you can create subtle curves or fully circular elements, improving user experience and adding elegance to your web projects.