CSS Academy · Lesson

Outline and Box-Shadow

Add focus outlines and shadow effects around elements using outline and box-shadow.

Lesson 4 of 413 steps

Outline and Box-Shadow is a free CSS Academy lesson on CoddyKit. This is lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.

outline Property

outline draws a line outside the border. It does not affect layout — elements around it do not shift. The shorthand format mirrors border: width style color.

<button class="focus-demo">Focused Button</button>

outline-offset

outline-offset moves the outline away from the border edge. Positive values push it outward; negative values move it inward (clipping effect).

<button class="focus-demo">Keyboard-focused Button</button>

outline vs border

Key differences:

  • Outline does not affect layout flow
  • Outline cannot be set per-side (no outline-top)
  • Outline can be non-rectangular (follows focus ring shapes in some browsers)
  • Outline is always outside the border

:focus-visible vs :focus

Prefer :focus-visible for keyboard focus rings. It shows the outline only when focus was received via keyboard, not mouse click — avoiding visual noise for pointer users while preserving accessibility.

<button class="focus-demo">Keyboard focus vs mouse click</button>

box-shadow Basics

box-shadow adds a shadow effect around an element. The shorthand: offset-x offset-y blur-radius spread-radius color.

<div class="card">Card with soft shadow</div>

box-shadow Values Explained

Each value in box-shadow:

  • offset-x: horizontal shift (negative = left)
  • offset-y: vertical shift (negative = up)
  • blur-radius: softness (0 = sharp)
  • spread-radius: grow/shrink shadow size
  • color: shadow color (RGBA recommended)
<div class="raised">Raised</div>
<div class="deep">Deep</div>

inset Box Shadow

Add the inset keyword to draw the shadow inside the element, creating a pressed/sunken appearance.

<input class="input focus-demo" type="text" value="Focused input" />

Multiple Box Shadows

Comma-separate multiple shadows. They stack from front to back:

<span class="badge">3</span>

box-shadow vs filter: drop-shadow

box-shadow respects the box shape only. filter: drop-shadow() follows the rendered shape including transparency — ideal for PNG icons with transparent backgrounds.

<div class="icon">&#9733;</div>

Elevation System with box-shadow

Material Design and similar systems define multiple shadow levels for visual elevation. Map CSS variables to shadow values:

<div class="elevation-sm">sm</div>
<div class="elevation-md">md</div>
<div class="elevation-lg">lg</div>

Animating box-shadow Efficiently

Animating box-shadow triggers repaint on every frame. For performance, animate opacity of a pseudo-element shadow or use filter: drop-shadow() which can be composited.

Quick Check

Which box-shadow keyword draws the shadow inside the element?

Recap

outline draws outside the border without affecting layout — use it for focus indicators. box-shadow adds depth shadows with offset, blur, spread, and color. Use inset for inner shadows. Multiple shadows can be layered with commas.

Free to start

Learn CSS with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
40
Lessons
159

Frequently Asked Questions

Is the “Outline and Box-Shadow” lesson free?

Yes — the full text of “Outline and Box-Shadow” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.

What will I learn in “Outline and Box-Shadow”?

Add focus outlines and shadow effects around elements using outline and box-shadow. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CSS Academy?

No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “Outline and Box-Shadow” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CSS Academy lesson?

Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Understanding Width Height Margin and Padding
  2. Border Styles Width and Color
  3. Box-Sizing: Content-Box vs Border-Box
  4. Outline and Box-Shadow
← Back to CSS Academy