Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 36 ยท Elements and Styles

Pseudo-States, Colors and Live Style Experiments

Force :hover and :focus, use the color picker and contrast checker, emulate dark mode and print, and debug animations, with runnable color and contrast calculators.

Some styles only appear while something is happening: the mouse is over a button, a field has keyboard focus, an animation is halfway through. These states vanish the moment you move the mouse to the DevTools window, which makes them hard to inspect. DevTools gives you ways to freeze them, plus a color picker that checks contrast as you design.

Forcing pseudo-states

In the Styles pane, click :hov (the pseudo-class button, near the top, beside .cls). A row of checkboxes appears: :active, :focus, :focus-visible, :focus-within, :hover, :target, :visited, and sometimes more. Tick one and DevTools applies that state to the selected element permanently, until you untick it or select something else.

This is how you:

  • Edit the :hover rule of a button without moving the mouse away.
  • Check that :focus-visible outlines are visible for keyboard users.
  • Look at :visited link colors.
  • Debug a dropdown that opens on :focus-within.

You can also right-click a node in the Elements panel and use Force state to select the same states.

The .cls button lets you add classes to the element temporarily: type a class name, press Enter, and it appears with a checkbox so you can toggle it. Use it to test "what does this look like with is-active?" without writing JavaScript.

If a tooltip or menu closes when you click into DevTools, either force :hover/:focus as above or pause the page: in the Sources panel, press F8 after setting a breakpoint (or use the Command Menu's Emulate a focused page option) so the page keeps its focused state while you inspect.

The color picker

Click any color swatch in the Styles pane to open the picker:

  • A spectrum and hue and alpha sliders to choose the color visually.
  • An eyedropper icon to pick any pixel on the page.
  • A value display that you can cycle between hex, RGB, HSL and newer formats (such as HWB, lab() and oklch()), by clicking the format label or pressing Shift+Click on the swatch.
  • A contrast ratio line comparing the text color with its background, with AA and AAA pass or fail marks.
  • A palette of colors already used on the page, so you can reuse them.

The contrast information is the most valuable. Accessibility guidelines (WCAG) require a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (AA level), and 7:1 and 4.5:1 for AAA.

Stand-in: converting colors

Colors can be written in several formats. This stand-in converts a hex color to RGB and to HSL, the same conversions DevTools does when you cycle the format. It is a plain JavaScript model with standard formulas.

JS Stand-in: hex to RGB and HSL

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Stand-in: the contrast checker

The contrast ratio comes from the relative luminance of the two colors. The formula is defined in the WCAG specification, and DevTools uses it in the picker. This calculator reproduces it.

JS Stand-in: WCAG contrast ratio

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Black on white gives exactly 21:1, the maximum. Mid-grays like #777 on white land just above 4.5, which is why that gray is a famous borderline. When the picker shows a contrast warning, it is the same arithmetic as above.

Emulating user preferences and media

Open the Command Menu, type Show Rendering, and the Rendering tool opens in the drawer. Among its options:

  • Emulate CSS media type (print or screen) to test print stylesheets.
  • Emulate CSS media feature prefers-color-scheme to test dark mode without changing your system settings.
  • Emulate prefers-reduced-motion and prefers-contrast and forced-colors to check accessible variants.
  • Emulate vision deficiencies (blurred vision, protanopia, deuteranopia, tritanopia, achromatopsia) to see the page through different color perceptions.
  • Paint flashing and Layout shift regions to see what repaints or moves.

These settings are tab-wide and reset when you close DevTools (some persist while open).

Inspecting animations

Open the Animations tool from the drawer menu. When an animation or transition starts on the page, a group appears in a timeline. You can:

  • Replay it slower (10%, 25%, 100%) to see details.
  • Drag the timeline to scrub to a specific moment.
  • Click an animation to select its element and edit its duration and delay values.

For CSS transitions that are too quick to catch, slowing them down is often all you need to see why a flicker occurs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you keep a button in its :hover state while you edit its CSS?

    The :hov checkboxes force a pseudo-state on the selected node until you untick it.
  2. 2. What is the minimum WCAG AA contrast ratio for normal-size text?

    AA requires 4.5:1 for normal text and 3:1 for large text; AAA requires 7:1 and 4.5:1.
  3. 3. Where do you emulate dark mode or reduced motion without changing system settings?

    Open the Rendering tool through the Command Menu or the drawer menu.
  4. 4. What does the .cls button in the Styles pane let you do?

    .cls adds temporary classes to the element so you can test how they look.

Summary

  • Force :hover, :focus, :active and others from the :hov panel; add temporary classes with .cls.
  • The color picker converts formats, samples pixels and shows WCAG contrast; aim for 4.5:1 or better on normal text.
  • The Rendering tool emulates print, dark mode, reduced motion and vision deficiencies.
  • The Animations tool slows down and replays transitions.

Next: Console Basics and Logging Methods