CSS Rounded Corners

To set rounded corners of an element, use the border-radius property in CSS. We can also set the radius for each corner. In this lesson, we will work around both examples.

Rounded Corners

Let us see an example to set rounded corners for a div:

<!DOCTYPE html>
<html>
<head>
<style> 
div {
  width: 150px;
  height: 150px;
  background-color: red;
  color: white;
  border: 2px solid black;
  padding: 10px;
}
.demo {
  border-radius: 25px;
}
</style>
</head>
<body>

<h1>CSS Rounded Borders Example</h1>

<div>
   <p>A box</p>
</div><br>
<div class = "demo">
   <p>A box with rounded corners</p>
</div>

</body>
</html>

Output

CSS Rounded Corners

Set different sizes for rounded corners

We can also set different sizes for all the rounded corners, i.e. top-left, top-right, bottom-left, and bottom-right. Let us see an example:

<!DOCTYPE html>
<html>
<head>
<style> 
div {
  width: 150px;
  height: 150px;
  background-color: red;
  color: white;
  border: 2px solid black;
  padding: 10px;
}
.demo {
  border-radius: 5px 20px 10px 50px;
}
</style>
</head>
<body>

<h1>CSS Rounded Borders Example</h1>

<div>
   <p>A box</p>
</div><br>
<div class = "demo">
   <p>A box with different rounded corners</p>
</div>

</body>
</html>

Output

CSS Rounded Corners for different corners

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


Read More:

CSS - 2D Transform
CSS - Transitions
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment