In this lesson, you checked the Hawthorn Seed Library catalogue under forced colors and found that its buttons lost their edges and its focus ring disappeared. You gave them edges drawn with a transparent border and outline, which forced colors keeps, and you made the seed cards’ borders stronger for visitors who ask for more contrast.
Key Points
- The catalogue’s focus ring comes from
outline: noneand abox-shadowwith no blur. Its color already passes 3:1 in both themes. - Some people can’t read pages in their designed colors. Windows gives them contrast themes. A person picks a few colors, such as light text on black, and the browser repaints every page with them. CSS calls this forced colors.
- To try it, open DevTools’ Rendering panel from the Command Menu (Ctrl+Shift+P, or Cmd+Shift+P on macOS, then Show Rendering) and set the forced-colors emulation, Emulate CSS media feature forced-colors, to
forced-colors: active. DevTools uses its own set of colors here. A person’s theme would use theirs. - In forced colors, the browser swaps the colors of text, backgrounds and borders for the person’s colors, and it sets every
box-shadowtonone. The focus ring was a box shadow, and the rule had already removed the outline, so a focused button showed nothing. Someone using the keyboard couldn’t see where they were. - Without its terracotta background, the button is plain blue text, like any link, so only an edge would show it’s a button.
- Borders and outlines survive forced colors. Only their color changes. The form’s Send request button was as bare as the Borrow seeds buttons.
- Each button gets
border: 2px solid transparent. Transparent is a color too, so forced colors replaces it, and in normal colors the button’s background shows through it. The focus rule replacesoutline: nonewithoutline: 2px solid transparentandoutline-offset: 2px. The offset keeps the ring apart from the button’s new edge. Thebox-shadowstays, so the ring looks as it did in normal colors. - The form’s Send request button had a more specific rule that set its border to
none. Deleting that line lets the new border reach it too. - Other people keep a page’s own colors but turn on a system setting for more contrast, which CSS reads through
prefers-contrast. The seed cards’ see-through borders only group content, so they don’t need 3:1, but underprefers-contrast: morethey now use the same green as the fields’ borders. The media query comes after the:rootrule that first declares--color-card-border, so it wins. Check it with Emulate CSS media feature prefers-contrast set toprefers-contrast: more, then set it back to No emulation. - The rule: draw edges and focus rings with borders and outlines, because forced colors removes every box shadow.
Colors That Follow the Person’s Theme
Forced colors repaints text, backgrounds and borders for you. When one of your own parts needs a particular color from the person’s palette, you can name it yourself with a system color keyword, usually inside a @media (forced-colors: active) query. These five cover most needs: