Open In App

How to Add a Rounded Border with CSS ?

Last Updated : 17 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A rounded border in CSS gives elements smooth, curved corners instead of sharp ones. It enhances design aesthetics and is achieved using the border-radius property. This allows developers to control the curvature, creating visually appealing and modern web layouts easily.

Using the border-radius property, you can easily add rounded borders to various HTML elements, enhancing their appearance and creating a more visually appealing layout.

Syntax

border-radius: 1-4 length|% / 1-4 length|%|initial|inherit

Example 1: Applying Rounded Borders to a div

In this example, we applies rounded borders to a div using the .RoundedBorder class. It sets a blue background, adjusts border radius to 75px, and centers the text with padding, width, and height.

html
<!DOCTYPE html>
<html>

<head>
    <style>
        .RoundedBorder {
            border-radius: 75px 75px;
            background: blue;
            padding: 16px;
            text-align: center;
            width: 300px;
            height: 120px;
        }
    </style>
</head>

<body>

    <h2>
        Adding Rounded Borders with CSS
    </h2>

    <div class="RoundedBorder">
        <h4>
            Rounded corners Borders
        </h4>
    </div>

</body>

</html>

Output:

round-corner

rounded border with CSS Example Output

Example 2: Applying Rounded Borders to a button

In this example, we will apply rounded borders to a button element. We are setting the height and width to be same and then setting the border-radius to 50% to get the button completely rounded.

HTML
<!DOCTYPE html>
<html>

<head>
    <style>
        .btn {
            border-radius: 50%;
            background: rgb(2, 138, 43);
            color: #fff;
            padding: 2px;
            text-align: center;
            width: 75px;
            height: 75px;
            border: solid 1px transparent;
        }
    </style>
</head>

<body>
    <h2>
        Adding rounded border to a button
    </h2>
    <button class="btn">Submit</button>

</body>

</html>

Output:

rounded-border-to-a-button

rounded border to a button



Next Article

Similar Reads

  翻译: