EN
CSS - how to round corners in a div
3 points
In this article, we would like to show you how to round corners in a div in CSS.
Quick solution:
xxxxxxxxxx
1
div {
2
border-radius: 20px;
3
}
There are several ways to round element but in this article, we present two of them depending on which corners we want to round:
- how to round all corners using
border-radius
property, - how to round selected corners.
Below example shows the use of a border-radius
property to make rounded <div>
element.
Runnable example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
div {
6
height: 100px;
7
width: 100px;
8
background-color: goldenrod;
9
border-radius: 20px; /* <---------- use this to round all corners in div */
10
}
11
</style>
12
</head>
13
<body>
14
<div></div>
15
</body>
16
</html>
Note:
border-radius
property can have from one to four values. Read more about the property here.
Below example shows how to round selected corners of the <div>
using border-top-left-radius
property for the top-left corner and the same for the other corners positions.
Runnable example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
div {
6
height: 100px;
7
width: 100px;
8
background-color: goldenrod;
9
border-top-left-radius: 25px; /* <----- top-left corner round */
10
border-top-right-radius: 30px; /* <----- top-right corner round */
11
border-bottom-right-radius: 40px; /* <----- bottom-right corner round */
12
border-bottom-left-radius: 50px; /* <----- bottom-left corner round */
13
}
14
</style>
15
</head>
16
<body>
17
<div></div>
18
</body>