CHAPTER 8

CSS Borders

CSS borders define visible boundaries around HTML elements.

01. What is CSS Borders?

border-width controls the thickness of a border.
border-style defines whether the border is solid, dashed, dotted and more.
border-color controls the border color.
Individual sides can have different borders.
border-radius can create rounded corners.

02. Syntax

.box { border: 2px solid blue; } .rounded { border-radius: 15px; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>

<head>

    <style>

        .card {

            width: 300px;

            padding: 25px;

            border:
                2px solid #2563eb;

            border-radius:
                18px;

            margin: 30px auto;

        }

    </style>

</head>

<body>

    <div class="card">

        <h2>
            AIFA Infotech
        </h2>

        <p>
            CSS Border Example
        </p>

    </div>

</body>

</html>

04. Important Points

✓ A border normally requires width, style and color.
✓ border-radius creates rounded corners.
✓ Different border properties can be applied to individual sides.

05. Common Mistakes

⚠ Using border without a visible border style.
⚠ Forgetting that border adds to the element's dimensions unless box-sizing is controlled.

06. Real World Use

Borders are widely used around cards, buttons, forms, navigation items and input fields.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Styled Card

Create a card with a 2px border, rounded corners, padding and a heading.