Style borders, outlines, corners, shadows, and opacity.
Borders, rounded corners, and shadows help a card or button stand out. Some add to its size; others only change how it looks.
Use this card:
.card {
box-sizing: border-box;
padding: 1rem;
border: 2px solid green;
background-color: honeydew;
}The border shorthand sets three features:
2px sets the line's thickness.solid draws a continuous line. Other styles include dashed and dotted.green supplies the line's color.A border occupies space in the box model. With border-box, it fits inside a declared width. Set a visible style: a border whose style is none does not draw a line.
To style one side independently, use a side-specific property such as border-bottom: 4px solid green.
.card {
border-radius: 12px;
}border-radius rounds the border and background corners without changing the box's rectangular layout dimensions. One value applies to all four corners.
A rounded card can still have a child that draws past a corner. Clipping overflow on the card can hide that child’s shadow or focus outline too. Tab to its link and check that the whole indicator remains visible.
An outline draws around a box without taking up layout space. It is useful for showing which link or control has keyboard focus:
.card a:focus-visible {
outline: 3px solid purple;
outline-offset: 3px;
}outline-offset moves the outline away from the edge. Unlike adding a border, adding an outline does not move neighboring content.
Tab to the card's link to inspect the indicator. Keep a visible focus indicator; removing the browser's outline without a suitable replacement makes keyboard navigation harder.
.card {
box-shadow: 0 4px 12px 0 rgb(0 0 0 / 15%);
}Read the values in order:
0 keeps the shadow centered horizontally.4px shifts it downward.12px softens its edge.0 adds no expansion before blurring.Box shadows do not reserve layout space. A large shadow can overlap nearby content even though the card's dimensions stay the same. Add inset for an inner shadow, or separate multiple shadows with commas.
.card {
opacity: 0.5;
}opacity: 0.5 makes the whole card partly transparent, including its text and child elements. A child cannot restore full opacity by setting opacity: 1.
To make only the background translucent, remove the opacity declaration and use a color with an alpha channel:
.card {
background-color: rgb(0 128 0 / 20%);
}The background blends with what is behind it while the text keeps its own opacity. Neither approach changes the space the card occupies.
border-radius rounds the border and background without automatically clipping children.opacity affects the whole element and its children. A background color with alpha changes only the background.Try it yourself
HTML + CSS