Sub topic 11
Hover, focus, active, disabled and error states
This chapter covers how to check the interactive states of a built page against the design. It assumes you can open DevTools, read a design frame, and know basic CSS selectors and the cascade. It builds on measuring with DevTools and reading the design as a source of truth.
A static screenshot shows one state of each component. Users see many more. A button is idle, hovered, pressed, focused and sometimes disabled. A text field can also be invalid. Designs often show these states on a separate frame or in a component library, and developers sometimes miss one. Your job is to trigger each state on the built page and compare it with the design.
The states and what to expect
| State | Triggered by | CSS hook | Typical design change |
|---|---|---|---|
| Hover | Pointer over the element | `:hover` | Background or underline change |
| Focus | Keyboard Tab or click on a field | `:focus`, `:focus-visible` | Outline or ring |
| Active | Pointer or key held down | `:active` | Darker fill, slight shift |
| Disabled | Attribute set by code | `:disabled`, `[aria-disabled="true"]` | Muted colors, no hover effect |
| Error | Failed validation | `:invalid`, `[aria-invalid="true"]`, a class | Red border, message text, icon |
Before testing, list every interactive component in the design: links, buttons, inputs, selects, checkboxes, radios, tabs, menu items and cards that act as links. For each one, note which states the design defines. A missing design for a state is itself a finding. Report it as a question for the designer, not as a bug.
Forcing states in DevTools
Most states are brief, so you cannot inspect them while you hold the mouse still. DevTools can force them.
- Select the element in the Elements panel.
- Open the Styles pane and click the
:hovtoggle (Chrome and Edge) or the:hovbutton in the Rules view (Firefox). - Tick
:hover,:focus,:active,:focus-visibleor:focus-within. - Read the changed values in the Styles and Computed panes.
With the state forced, you can measure it the same way as the idle state. Compare background color, border, shadow, text color and size against the spec.
You can also read the values from the console. This snippet logs the properties that states usually change. Force a state first, then run it.
const el = document.querySelector('button.primary');
const s = getComputedStyle(el);
console.log({
backgroundColor: s.backgroundColor,
color: s.color,
borderColor: s.borderColor,
boxShadow: s.boxShadow,
outline: s.outline,
textDecoration: s.textDecorationLine,
cursor: s.cursor,
opacity: s.opacity
});Run it once per state and compare the output. A cursor of not-allowed or pointer is part of the design too, though designs rarely show it. Check that disabled controls do not show a pointer.
Hover
Check each hoverable element for these points.
- The change matches the design: color, underline, shadow, scale.
- The transition exists if the design specifies one. A change from 0 to 200 ms is hard to see in a screenshot, so read
transitionin the Computed pane. - The hover area matches the element. Padding on a link may be clickable in the design but not in the build, or the reverse.
- Nothing shifts layout. A border that grows from 0 to 1px on hover moves neighbors by one pixel. Look for jumps when you hover.
Touch devices have no true hover. On a phone, a tap can leave an element stuck in the hover state. Test on a real device or use device mode, and check that hover-only content, such as a dropdown that opens on hover, can also be reached by tap and keyboard.
Focus
Focus is where builds most often diverge from designs, because browsers supply a default outline and developers frequently remove it with outline: none.
Tab through the whole page with the keyboard and watch for these problems.
- An element that takes focus but shows no visible change.
- A focus ring clipped by a parent with
overflow: hidden. - A ring with low contrast against its background. WCAG 2.2 asks for a contrast ratio of at least 3:1 between the focused and unfocused appearance.
- A custom component, such as a
divwith a click handler, that cannot be reached by Tab at all. - Focus order that jumps around the page instead of following the visual order.
:focus applies to any focused element, including a button clicked with a mouse. :focus-visible applies when the browser decides a ring is useful, usually for keyboard use. Designs usually show the keyboard ring, so test with Tab and not with clicks. For text inputs, browsers show the ring on both mouse and keyboard focus.
/* A focus style that is visible for keyboard users and does not rely on the default */
button:focus-visible,
a:focus-visible {
outline: 2px solid #1a56db;
outline-offset: 2px;
}Active
The active state lasts only while the control is pressed, so force it with :active in DevTools. Compare it with the design. Confirm that it differs from hover, since a build that reuses the hover styles for both is common. Also check keyboard activation: pressing Space on a button should show the same pressed look as a mouse press.
Disabled
A disabled control tells users that an action is unavailable. Check these points.
- Colors match the disabled style in the design, not just a lowered
opacitythat the designer never specified. - Hover and active styles do not apply. A disabled button that still darkens on hover looks clickable.
- Text still meets the contrast the design intended. WCAG exempts inactive controls from contrast requirements, but a label that is unreadable still hurts users, so raise it as a question.
- The element is really disabled. Click it and press Enter on it. Nothing should happen.
There are two ways to disable, and they differ. The disabled attribute removes the control from the tab order. aria-disabled="true" keeps it focusable and only describes it as unavailable, so developers must block the action in code. Either can be correct. Verify the build behaves consistently with the rest of the product.
Error states
Error states have the most parts, so check each one.
- Trigger the error with real input: leave a required field empty, enter an invalid email, or submit a bad form.
- Compare the field itself: border color, border width, background and any icon.
- Compare the message: text color, size, position and spacing from the field.
- Check that color is not the only signal. A red border alone fails users with color vision deficiency. The design should also include an icon or text.
- Check the focused error state, which combines two states. A focus ring on an invalid field must still be visible.
- Fix the error and confirm the field returns to its normal look.
Long error messages and several errors at once are layout tests. Submit an empty form and check that the messages do not overlap the next field.
Common errors
- Forgetting stacked states. A button can be hovered and focused at once. Force both and check the result.
- Testing only the primary button. Secondary, tertiary and icon buttons often have their own state styles.
- Trusting the cursor to show focus. Mouse position tells you nothing about keyboard focus.
- Stale cached styles. Hard reload before comparing, so you do not review an older build.
- Pass or fail by eye on subtle color shifts. A hover change from
#1a56dbto#1648b8is easy to miss. Read the computed value.
Recording what you find
For each defect, record the component, the state, the viewport, the browser, and the expected and actual values. For example: "Primary button, hover, 1280 px, Chrome 130. Expected background #1648b8, actual #1a56db. No change on hover." This feeds directly into the reporting chapter later in the tutorial.
Exercise
A designer's frame shows a text input with a red border and an error message when the email is invalid. On the built page, the border turns red, but keyboard users report they cannot tell when the field has focus after the error appears. Which states do you test and what do you check?
Show answer
Test the combined focused and invalid state. Tab into the invalid field, or force :focus-visible in DevTools on a field that has the error class or aria-invalid="true". Check that a focus ring is visible, has at least 3:1 contrast against the background, and is not hidden by the red border style or by outline: none. Also confirm the error message is still shown and that color is not the only error signal.
Exercise
A disabled submit button looks correct, but clicking it still sends the form. What is the likely cause, and how can you tell which disabling method the developer used?
Show answer
The button is probably styled as disabled, for example with a class or aria-disabled="true", without blocking the action. Inspect the element: if it has no disabled attribute, it is still active and can be focused with Tab. A real disabled attribute removes it from the tab order and prevents the click. Report it as a behavior defect, since the visual match to the design hides a functional problem.