CSS - Borders & Outline
Overview
Quick links: Exercises • Checks • Print as PDF
Estimated time: 8–12 minutes
Use borders for element boundaries and outlines for accessible focus without shifting layout.
Learning Objectives
- Apply border shorthands and rounded corners.
- Use
outline
andoutline-offset
for focus styles.
Details & Examples
border
shorthand: width style colorborder-radius
: rounded cornersoutline
andoutline-offset
: focus rings that don’t affect layout
Rounded corner box
Checks for Understanding
- Why might you prefer
outline
overborder
for focus?
Show answers
- Outlines don’t affect layout and won’t cause content shifts.
Exercises
- Create an accessible focus outline using
outline
andoutline-offset
. - Build a pill button with rounded corners and a subtle border.
Suggested answers
:focus-visible{ outline:3px solid #34d399; outline-offset:2px; }
.btn{ border-radius:999px; border:1px solid var(--border); }