Skip to content

fix: Make target background of references accessible in dark mode#5165

Open
TimvdLippe wants to merge 2 commits intospeced:mainfrom
Logius-standaarden:fix-references-hover-styling
Open

fix: Make target background of references accessible in dark mode#5165
TimvdLippe wants to merge 2 commits intospeced:mainfrom
Logius-standaarden:fix-references-hover-styling

Conversation

@TimvdLippe
Copy link
Copy Markdown
Collaborator

Reported in our documents that the light blueish background for targeted references is not accessible:
Logius-standaarden/publicatie#57

Instead, we can use the same styling as we have for var(--borderedblock-bg) (which are used for examples), except make its opacity higher (5% to 30%).

Reported in our documents that the light blueish background for
targeted references is not accessible:
Logius-standaarden/publicatie#57

Instead, we can use the same styling as we have for
`var(--borderedblock-bg)` (which are used for examples), except
make its opacity higher (5% to 30%).
@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

With the new styling for dark mode:

Screenshot 2026-04-07 at 11 28 03

@TimvdLippe TimvdLippe changed the title Make hover background of references accessible in dark mode fix: Make hover background of references accessible in dark mode Apr 7, 2026
@marcoscaceres marcoscaceres requested a review from Copilot April 8, 2026 13:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the ReSpec stylesheet to improve the visibility/accessibility of the “targeted reference” highlight in dark mode (per Logius-standaarden/publicatie#57).

Changes:

  • Add a prefers-color-scheme: dark override for #references :target background styling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


@media (prefers-color-scheme: dark) {
#references :target {
background: rgb(255 255 255 / 30%);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a hard-coded dark-mode highlight color (rgb(255 255 255 / 30%)), while the PR description indicates the intent is to reuse the same styling as var(--borderedblock-bg) with a higher opacity. To keep theme consistency if the underlying ReSpec variables change, consider basing this highlight on the existing variable (or updating the PR description to match the implementation).

Suggested change
background: rgb(255 255 255 / 30%);
background: color-mix(
in srgb,
var(--borderedblock-bg) 70%,
transparent
);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never used color-mix myself, so I don't know if this is the right syntax.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll take a look and see if I can get something rough working locally

@TimvdLippe TimvdLippe changed the title fix: Make hover background of references accessible in dark mode fix: Make target background of references accessible in dark mode Apr 8, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@marcoscaceres
Copy link
Copy Markdown
Contributor

The bug being fixed is real — #eaf3ff in dark mode renders light text on a light blue background, which fails contrast badly. But the fix has a scoping issue that could cause a regression.

The problem with the current approach

ReSpec defaults to color-scheme: light (style.js:122), and dark.css is only loaded when a spec author explicitly opts into dark mode (style.js:125: if (colorScheme.content.includes("dark"))). However, the fix lives in respec.css.js — always bundled — and uses @media (prefers-color-scheme: dark), which fires based on OS preference regardless of what color-scheme the page declares.

So for any spec using the default color-scheme: light (the majority of specs), a user with a dark OS theme still triggers the new rule. The W3C base.css sets --bg: white in :root with no dark mode override of its own, so the body stays white. Compositing rgb(255 255 255 / 30%) over a white background makes the #references :target highlight invisible — a regression from the original #eaf3ff for those users.

Suggested fix

Remove the @media block from respec.css.js and instead inject an inline <style> inside the existing if (colorScheme.content.includes("dark")) block in src/w3c/style.js, so it only applies to specs that have actually opted into dark mode:

if (colorScheme.content.includes("dark")) {
  const darkModeStyleUrl = getStyleUrl("dark.css");
  document.head.appendChild(
    html`<link
      rel="stylesheet"
      href="${darkModeStyleUrl.href}"
      media="(prefers-color-scheme: dark)"
    />`
  );
  document.head.appendChild(
    html`<style media="(prefers-color-scheme: dark)">
      #references :target { background: rgb(255 255 255 / 30%); }
    </style>`
  );
  sub("beforesave", styleMover(darkModeStyleUrl));
}

This keeps the fix scoped to specs where dark mode is actually active, avoiding the regression for the default case.

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.

3 participants