Interaction states and form styling
Style hover, focus, disabled, and invalid states while preserving visible keyboard focus.
- Difficulty
- beginner
- Time
- 40 minutes
- Last verified
- 9/21/2026
What you will build
Style hover, focus, disabled, and invalid states while preserving visible keyboard focus.
Understand the idea first
Never remove outlines without an equivalent replacement.
Build it step by step
a:hover {
color: #9a3412;
}
:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 3px;
}
input,
textarea,
select,
button {
font: inherit;
}
input:invalid:not(:placeholder-shown) {
border-color: #b91c1c;
}
button:disabled {
opacity: 0.55;
cursor: not-allowed;
}- Tab through the page before and after adding focus-visible.
- Make controls inherit typography and provide generous targets.
- Enter an invalid email and keep native text feedback.
- Verify both hover and focus states.
Read the important lines
- Never remove outlines without an equivalent replacement.
:focus-visibleemphasizes keyboard focus.- Errors need text, not color alone.
Common mistakes and what to check
| Symptom | What to check |
|---|---|
| Focus disappears | Check whether a reset removed outlines. |
| Button contrast fails | Check normal, hover, and disabled states separately. |
Practice without copying
Finish normal, focus, invalid, and disabled form states and capture evidence.
Check the answer after you try
All four states are distinct; focus is obvious and labels remain readable.
Completion check
- I produced the required visible result
- I can explain the input, processing, and output
- I tested normal, edge, and failure cases