Skip to content

CSS Borders

Overview

Borders are used to create visual boundaries around elements.

Basic Border Properties

css
.element {
    border-width: 2px;
    border-style: solid;
    border-color: #333;
}

/* Shorthand property */
.element {
    border: 2px solid #333;
}

Border Styles

css
.solid-border {
    border: 2px solid #000;
}

.dashed-border {
    border: 2px dashed #666;
}

.dotted-border {
    border: 2px dotted #999;
}

.double-border {
    border: 3px double #333;
}

Individual Border Sides

css
.element {
    border-top: 2px solid red;
    border-right: 2px solid blue;
    border-bottom: 2px solid green;
    border-left: 2px solid yellow;
}

Border Radius (Rounded Corners)

css
.rounded {
    border-radius: 10px;
}

.circle {
    border-radius: 50%;
    width: 100px;
    height: 100px;
}

.different-corners {
    border-radius: 10px 20px 30px 40px; /* top-left top-right bottom-right bottom-left */
}

Advanced Border Techniques

Gradient Borders

css
.gradient-border {
    border: 3px solid;
    border-image: linear-gradient(45deg, red, blue, green);
    border-image-slice: 1;
}

Outline vs Border

css
.outline-example {
    border: 2px solid blue;
    outline: 2px solid red;
    
    /* Outline doesn't affect layout */
    /* Border affects box model */
}

Common Patterns

Card Design

css
.card {
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

Button Borders

css
.button {
    border: 2px solid #007bff;
    border-radius: 4px;
    background-color: #007bff;
    color: white;
    padding: 8px 16px;
}

Content is for learning and research only.