Outlines and shadows
Definition and purpose
An outline draws outside or around a box without taking layout space. Box shadows add decorative depth. Keyboard focus needs a visible indicator, not merely decorative shadows.
Keyboard focus ring
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a:focus-visible { outline: 3px solid navy; outline-offset: 3px; } </style> </head> <body> <button id="a">Save</button> </body></html>Press Tab to focus the button; a separated outline appears.
Syntax and mental model
outline: 3px solid navy; outline-offset: 3px separates a visible ring from a control. box-shadow: 0 4px 12px rgb(0 0 0 / .2) sets x/y offsets, blur and color. :focus-visible is useful for keyboard focus while preserving native fallback behavior.
Decorative shadow
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { background: white; padding: 16px; box-shadow: 0 4px 12px rgba(0,0,0,.2); } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>A soft shadow is painted without adding layout width.
Common mistakes
Never remove native focus without a reliable visible replacement. Shadows may disappear in forced colors; keep outline or border cues and test keyboard interaction.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Borders and rounding. Next lesson: Border images and opacity.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Outlines and shadows — knowledge check
Five questions on outlines and shadows.
Does outline take normal layout space?
Which separates outline from the box?
Which is a suitable keyboard focus selector?
Why not rely solely on a shadow in forced colors?
What is required before removing native focus?