Borders, rounded corners, and elevation drop-shadows provide tactile depth, visual structure, and clear boundary separation for user interface components like buttons, input fields, cards, and modal dialogs.
The border shorthand combines width, style, and color in a single declaration:
/* Syntax: border: [width] [style] [color]; */
.card {
border: 1px solid #e2e8f0;
border-top: 4px solid #d22b2b; /* Accent header line */
}
Supported border styles include: solid, dashed, dotted, double, groove, ridge, inset, outset, and none.
The border-radius property rounds the corners of an element without needing background images:
/* 1. Subtle card corner rounding */
.card { border-radius: 8px; }
/* 2. Full Pill / Stadium Button */
.pill-button {
padding: 12px 28px;
border-radius: 9999px;
background: #d22b2b;
color: #fff;
}
/* 3. Perfect Avatar Circle (Requires equal width & height) */
.avatar {
width: 80px;
height: 80px;
border-radius: 50%;
object-fit: cover;
}
| Feature | CSS Border | CSS Outline |
|---|---|---|
| Box Model Impact | Occupies physical space; affects element dimensions. | Drawn outside the box model; takes zero space. |
| Individual Sides | Can style sides independently (border-left). |
Surrounds all 4 sides equally; cannot style one side. |
| Offset Spacing | Glued directly to padding boundary. | Supports outline-offset: 3px; to create floating rings. |
| Primary Role | Permanent visual structural perimeter. | Keyboard focus indicators for accessibility compliance. |
Flat single-value shadows often look harsh. Top frontend design systems (Tailwind, Material Design) achieve realistic ambient lighting by stacking two subtle shadows:
/* Syntax: box-shadow: [x-offset] [y-offset] [blur] [spread] [color]; */
.elevated-card {
background: #ffffff;
border-radius: 8px;
box-shadow:
0 1px 3px 0 rgba(0, 0, 0, 0.1),
0 1px 2px -1px rgba(0, 0, 0, 0.1);
transition: box-shadow 0.2s ease;
}
.elevated-card:hover {
box-shadow:
0 10px 15px -3px rgba(0, 0, 0, 0.1),
0 4px 6px -4px rgba(0, 0, 0, 0.1);
}
Boost your CSS and front-end development proficiency by exploring these closely connected topics:
Understand margins, borders, padding, content and the universal box-sizing fix.
Master 1D alignment, justify-content, align-items, flex-wrap and responsive flow.
Build powerful two-dimensional grid layouts with template areas and fr units.
Eliminate styling conflicts and master selector weights from 0,0,0,1 to !important.