Skip to content

feat(ui): declare color scheme and add forced-colors fallbacks - #22577

Open
slick-daddy wants to merge 1 commit into
lichess-org:masterfrom
slick-daddy:fix/color-scheme-forced-colors
Open

slick-daddy wants to merge 1 commit into
lichess-org:masterfrom
slick-daddy:fix/color-scheme-forced-colors

Conversation

@slick-daddy

@slick-daddy slick-daddy commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

Lichess has no forced-colors support, no color-scheme declaration, and no font-size-adjust. This adds all three so high-contrast users get readable colors, native controls match the chosen theme, and text stays stable when Noto Sans loads.

What changed

  • Added <meta name="color-scheme" content="light dark"> to the shared page head.
  • Declared color-scheme: light dark on :root and color-scheme: light on html.light.
  • Mapped the core color tokens to system color keywords under @media (forced-colors: active).
  • Added font-size-adjust: from-font to the html font rule.

Scope

Lichess lets users pick system, light, or dark themes, and OS preference only drives the theme in system mode. A bare light dark declaration would let the OS pick native control colors even when a user chose a different Lichess theme. That flips scrollbars and form controls to dark for light-theme users on a dark OS. The html.light override prevents that. Users who pick dark keep the existing scoped input override in _form.scss.

The forced-colors block names each theme class explicitly. html.light outranks :root, so a :root-only override would not apply to light themes. Existing scoped color-scheme rules for inputs, boards, date pickers, and the PayPal iframe stay as they are.

No tests were added. These are declarative CSS and meta changes that need visual verification under a high-contrast OS setting and with both light and dark themes.

Modern Web Guidance

  • color: I mapped text, background, border, link, and primary tokens to CanvasText, Canvas, LinkText, and Highlight, and left forced-color-adjust alone. The guide says "Define system color fallbacks for color tokens using @media (forced-colors: active)", which keeps native high-contrast colors without preserving aesthetics at the cost of readability.
  • dark-mode: I added both the head meta tag and the root declaration, then pinned html.light so UA surfaces follow the chosen theme. The guide requires "MANDATORY: Apply color-scheme to :root or html for viewport-wide theming", and the pin avoids a regression for users whose site theme differs from their OS.
  • visually-stable-font-fallbacks: I put font-size-adjust: from-font on html so every descendant inherits it. The guide marks it "MANDATORY: Normalize the font size based on the primary font's x-height", which prevents layout shift while the local Noto Sans font loads.

AI assistance

AI-assisted with OpenCode.

@slick-daddy
slick-daddy marked this pull request as ready for review November 19, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址