Rounded corners in css add a touch of elegance to web design by softening the edges of elements. In CSS, you can achieve rounded corners using different techniques and properties.
The 'border-radius'
property is the fundamental CSS property for creating rounded corners.
/* Apply rounded corners to an element */
.rounded-box {
border-radius: 10px; /* All corners have a radius of 10px */
}
Specify different radii for each corner using the 'border-top-left-radius'
, 'border-top-right-radius'
, 'border-bottom-left-radius'
, and 'border-bottom-right-radius'
properties.
/* Apply different radii to each corner */
.custom-rounded-box {
border-top-left-radius: 20px;
border-top-right-radius: 10px;
border-bottom-left-radius: 15px;
border-bottom-right-radius: 25px;
}
Use two values in the 'border-radius'
property to create elliptical or oval-shaped corners.
/* Create elliptical-shaped corners */
.ellipse-box {
border-radius: 20px 10px; /* Horizontal radius: 20px, Vertical radius: 10px */
}
Utilize percentage values for relative corner radii based on the element’s size.
/* Set rounded corners using percentage values */
.percent-rounded-box {
border-radius: 10%; /* All corners have a radius of 10% of the box size */
}
Use transparent borders to create gaps between rounded corners.
/* Create gaps between rounded corners */
.gapped-box {
border: 10px solid transparent;
border-radius: 20px;
}
Employ the 'clip-path'
property for more complex and custom shapes.
/* Create a custom-shaped element with clip-path */
.custom-shape {
clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 100%, 0 80%);
}
Rounded corners in CSS offer a simple yet effective way to enhance the visual appeal of your web designs. The 'border-radius' property, along with its variations, provides the flexibility to create rounded corners for various elements. Happy Coding! ❤️