Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › CSS Snippets › Reference › border

CSS Reference

border

Draws a line around an element. Shorthand for width, style, and color.

Last updated: October 2026

Definition: The border property draws a line around an element. It is shorthand for border-width, border-style, and border-color. Borders are part of the box model — they take up space and affect layout.

🎬 Live Examples

Every style, plus border-radius in action.

border-style values
solid
dashed
dotted
double
groove
ridge
border-radius
4px
12px
pill
circle
Individual sides
Top blue, left amber, others none

💡 Every example above uses the same border shorthand syntax — only the values change.

📝

Basic Syntax

/* Border shorthand: width | style | color */
.border {
    border: 2px solid #3b82f6;
}

/* Style is required for the border to appear */
.border-missing {
    border: 2px red;  /* Does nothing without a style */
}

Order doesn't matter in the shorthand — but the style must be present.

🎯 All border Sub-Properties

Property Purpose
borderShorthand for all three (width, style, color).
border-widthThickness: 1px, thin, medium, thick.
border-stylesolid, dashed, dotted, double, groove, ridge, inset, outset, none.
border-colorAny color value. Defaults to the element's text color.
border-radiusRounds the corners. Separate from the border shorthand.
border-top, -right, -bottom, -leftSet borders on individual sides.
border-collapseFor tables — collapse or separate cell borders.
1

The 10 border Styles

Style Look
solidSingle solid line. Most common.
dashedDashes.
dottedDots.
doubleTwo parallel lines.
groove3D carved effect.
ridge3D raised effect.
insetLooks pressed in.
outsetLooks popping out.
noneNo border.
hiddenLike none, but in tables it hides the shared border.

Use solid 95% of the time. Others have niche uses.

2

border-radius — Rounded Corners

/* Uniform radius */
.card {
    border-radius: 12px;
}

/* Pill shape */
.btn-pill {
    border-radius: 9999px;
}

/* Circle (needs equal width and height) */
.avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
}

/* Top corners only */
.tabs {
    border-radius: 8px 8px 0 0;
}

The border-radius shorthand takes the same 1–4 value pattern as margin and padding — top-left, top-right, bottom-right, bottom-left.

3

Individual Sides

/* Only top border */
.section {
    border-top: 2px solid #1e293b;
}

/* Only left accent border */
.quote {
    border-left: 4px solid #3b82f6;
    padding-left: 1rem;
}

/* Combining — border + border-top override */
.card {
    border: 1px solid #1e293b;
    border-top: 4px solid #3b82f6;  /* Accent */
}

Individual sides override the shorthand. This is how accent borders are built.

4

Common Border Patterns

/* Subtle border (dark mode) */
.card {
    border: 1px solid #1e293b;
}

/* Hover border glow */
.card:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Focus ring (accessibility) */
button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Divider line */
hr,
.divider {
    border: none;
    border-top: 1px solid #1e293b;
    margin: 1rem 0;
}

/* Input with error state */
input.error {
    border: 2px solid #ef4444;
}

/* Success input */
input.success {
    border: 2px solid #10b981;
}

🎯 border vs outline vs box-shadow

Feature border outline box-shadow
Takes up spaceYesNoNo
Affects layoutYesNoNo
Can be roundedYes (radius)Rounded corners on modern browsersYes (via spread)
Follows border-radius—SometimesYes
Common useCard borders, dividersFocus ringsGlow, elevation

💡 Rule: Use border for permanent lines. Use outline for focus indicators. Use box-shadow for glow or soft elevation without affecting layout.

⚠️ Common Mistakes

♿ Accessibility Notes

❓ Frequently Asked Questions

What is the CSS border property?

The border property draws a line around an element. It is a shorthand for border-width, border-style, and border-color. You can also use it to draw borders on individual sides.

What is the difference between border and outline?

Border is part of the element's box model — it takes up space and affects layout. Outline is drawn outside the element, does not take up space, and does not affect layout. Outlines are commonly used for focus indicators.

What is border-radius?

border-radius rounds the corners of an element. It is a separate property from border, not part of the border shorthand. Use values like 8px for subtle rounding or 9999px for pill-shaped buttons.

Why is my border not showing?

Borders require a style. border: 2px solid red works. border: 2px red does not. The most common mistake is setting width and color but forgetting the style value.

What are the border-style values?

The values are: none, hidden, solid, dashed, dotted, double, groove, ridge, inset, and outset. Solid is by far the most common.

🎯 What's Next?

← All CSS Reference