SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
The Box Model and SizingWriting Modes and Logical PropertiesSizing ElementsBorders and ShadowsDisplay and Document FlowNormal FlowFloats and ColumnsPositioning and StackingStacking and Z-Index Measuring boxes and predicting their positions
Box Model and Flow

Borders and Shadows

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.

Draw a border

Use this card:

.card {
  box-sizing: border-box;
  padding: 1rem;
  border: 2px solid green;
  background-color: honeydew;
}

The border shorthand sets three features:

  • Width: 2px sets the line's thickness.
  • Style: solid draws a continuous line. Other styles include dashed and dotted.
  • Color: 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.

Round the corners

.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.

Mark focus with an outline

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.

Add a box shadow

.card {
  box-shadow: 0 4px 12px 0 rgb(0 0 0 / 15%);
}

Read the values in order:

  • Horizontal offset: 0 keeps the shadow centered horizontally.
  • Vertical offset: 4px shifts it downward.
  • Blur radius: 12px softens its edge.
  • Spread radius: 0 adds no expansion before blurring.
  • Color: Translucent black makes the shadow subtle.

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.

Distinguish opacity from background transparency

.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.

Key Takeaways

  • Borders: Set a line’s width, style, and color. Its thickness counts toward the box’s size.
  • Corners: border-radius rounds the border and background without automatically clipping children.
  • Outlines: Focus indicators can surround a box without shifting the layout.
  • Shadows: Decorative shadows add visual depth without reserving space.
  • Opacity: opacity affects the whole element and its children. A background color with alpha changes only the background.

Try it yourself

Try it yourself

Give the order card an edge

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

How is this lesson?

Previous lessonSizing ElementsNext lessonDisplay and Document Flow
Edit on GitHubReport on GitHub
On this page
%

On this page

Draw a borderRound the cornersMark focus with an outlineAdd a box shadowDistinguish opacity from background transparencyKey TakeawaysTry it yourself