How to add rounded corner to an element using CSS?


Rounded corners add a soft and smooth look to a website and make it more visually appealing. It is a subtle design element that can make a big difference in the overall look and feel of a website.

In CSS, a rounded corner is a design element that creates a rounded edge on the corners of an HTML element, such as a div, a button, a form, or an image. The "border-radius" property is used to create rounded corners in CSS. The value of this property determines the radius of the rounded corners. The "border-radius" property can be applied to all four corners of an element at the same time, or to specific corners individually.

Properties in CSS to Create Round Corners

In CSS, there are several properties that can be used to create rounded corners on elements −

  • "border-radius" is a shorthand property that can be used to set the radius of all four corners of an element at the same time. The value can be a single value, which will be applied to all four corners, or up to four values, which will be applied to the top-left, top-right, bottom-right, and bottom-left corners, respectively.

  • "border-top-left-radius", "border-top-right-radius", "border-bottom-right-radius", and "border-bottom-left-radius" are the individual properties that can be used to set the radius of specific corners of an element.

  • "border-top-left-radius" and "border-top-right-radius" properties can be used to set the radius of top left and top right corners, respectively.

  • "border-bottom-left-radius" and "border-bottom-right-radius" properties can be used to set the radius of bottom left and bottom right corners respectively.

  • "border-radius 50%" can be used to create circular shapes.

These properties use together or individually to create unique and creative rounded corner designs for elements on a website. it use to add a soft and smooth look to an element, and make it more visually appealing. The border-radius property is widely supported by modern web browsers and can be used to create rounded corners on elements such as divs, buttons, forms, and images.

Add rounded corner to an element using CSS

Rounded corners are a popular design element that can add a soft and smooth look to any element. In this tutorial, we will go through the process of adding rounded corners to an element using CSS step by step, with examples.

Step 1: Identify the element

The first step is to identify the element that you want to add rounded corners to. This can be any HTML element such as a div, a button, a form, or an image. Let's take a div element as an example.

<div class="box"></div> 

Step 2: Add the CSS property "border-radius"

The next step is to add the CSS property "border-radius" to the element. The value of this property determines the radius of the rounded corners. For example, a value of "10px" will create corners with a 10px radius.

box {
   border-radius: 10px;
} 

Step 3: Specify different values for each corner

You can also specify different values for the border-radius property for each corner. This can be done by using the shorthand property "border-radius" and specifying values for each corner in the order of top-left, topright, bottom-right, bottom-left.

.box {
   border-radius: 10px 20px 30px 40px;
}

This will create corners with a radius of 10px for the top-left corner, 20px for the top-right corner, 30px for the bottom-right corner, and 40px for the bottom-left corner.

Step 4: Use the individual properties

If you want to create rounded corners on only certain corners of the element, you can use the individual properties "border-top-left-radius", "border-top-right-radius", "border-bottom-right-radius", and "border-bottom-left-radius".

.box {
   border-top-left-radius: 10px;
   border-top-right-radius: 20px;
   border-bottom-right-radius: 30px;
   border-bottom-left-radius: 40px;
} 

Step 5: Create circular shape

To create a circular shape, you can use "border-radius:50%".

.box {
   border-radius: 50%;
} 

Example

This example describes the use of border-radius property to make a rounded corner at the bottom left.

<!DOCTYPE html>
<html>
<head>
   <style>
      body{
         text-align:center;
      }
      #box1 {
         border-radius: 25px;
         background: #6ffc03;
         padding: 20px;
         width: 150px;
         height: 150px;
      }
      #box2 {
         border-radius: 25px;
         border: 2px solid #8AC007;
         background: #46637a;
         padding: 20px;
         width: 150px;
         height: 150px;
      }
   </style>
</head>
<body>
   <p id = "box1">Rounded corners!</p>
   <p id = "box2">Rounded corners!</p>
</body>
</html>

Example

This example describes the use of “border-bottom-left-radius” and “border-top-right-radius” property to make a rounded corner at the bottom left.

<html>
<head>
   <style>
      body{
         text-align:center;
      }
      #box1 {
         border-bottom-left-radius: 50px;
         background: #6ffc03;
         padding: 20px;
         width: 150px;
         height: 150px; 
      }
      #box2 {
         border-top-right-radius: 50px;
         border: 2px solid #8AC007;
         background: #46637a;
         padding: 20px;
         width: 150px;
         height: 150px;
      }
   </style>
</head>
<body>
   <p id = "box1">Rounded corners!</p>
   <p id = "box2">Rounded corners!</p>
</body>
</html>

Conclusion

Adding rounded corners to elements using CSS is a simple and easy process that can be done by using the "border-radius" property and its variations. With a little bit of practice, you can create beautiful designs with rounded corners that will enhance the overall look and feel of your website.

Updated on: 09-Mar-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements