Good Code
The good version keeps mouse hover, keyboard focus, and selected state distinct, so each user interaction has a visible and meaningful style.
Lesson 07
Style hover, active, selected, and keyboard focus states as separate reviewable behavior.
.tab-button {
/* Hover, focus, and selected state each get a distinct visual signal. */
color: #334155;
border-bottom: 2px solid transparent;
}
.tab-button:hover {
color: #0f172a;
}
.tab-button:focus-visible {
outline: 3px solid #f59e0b;
outline-offset: 3px;
}
.tab-button[aria-selected="true"] {
color: #1d4ed8;
border-bottom-color: currentColor;
}.tab-button {
/* Removing outline without a replacement hides keyboard position. */
outline: none;
}
.tab-button:hover,
.tab-button:focus {
color: #1d4ed8;
}
.tab-button.active {
border-bottom: 2px solid #1d4ed8;
}The good version keeps mouse hover, keyboard focus, and selected state distinct, so each user interaction has a visible and meaningful style.
The bad version removes the native outline and blends focus with hover, making keyboard navigation harder to detect and tying selected state to a visual-only class.