Skip to content

Five light-mode code token colours fall short of WCAG AA contrast #172

Description

@mmcky

Found while building Phase 3 (#89, landed in #171). The code-token palette the theme now ships is quantecon-book-theme's own (_code.scss), reproduced for parity. Measured against the white ground the theme's code blocks sit on (bg-stone-200/10 over white), five of its light-mode colours fall short of the WCAG 2.1 AA minimum of 4.5:1 for normal text. Code blocks render at text-sm, so the 3:1 large-text allowance does not apply. Every dark-mode value passes.

Token Sphinx class Colour Contrast on white AA
f-string substitution .si #70a0d0 2.75:1
comment .c .c1 #60a0b0 2.94:1
number .m .mi .mf #40a070 3.24:1
variable (non-Python) .nv #bb60d5 3.65:1
class name .nc #0e84b5 4.21:1
string .s #4070a0 5.19:1
keyword, builtin .k .nb #007020 6.29:1
decorator .nd #555555 7.46:1
function name .nf #06287e 13.02:1

Comments and numbers are the ones that matter in practice: every lecture code cell has both. The text colour scheme that landed alongside is fine (em 7.49:1, strong 5.73:1, inline literals 4.54:1).

This is a two-theme decision, not a fix for this repo alone. The values are the Sphinx builds' as deployed today, and #171 reproduced them deliberately so the migrated sites look like the current ones. Changing them here only would reintroduce a difference the parity work exists to remove; changing them means the same change in quantecon-book-theme's _code.scss, or accepting that the two stacks diverge on this point until the cutover.

If the decision is to fix, the nearest darker shade of each hue that reaches AA, keeping the palette's character:

Token Today Candidate Contrast
comment #60a0b0 #447c89 4.68:1
number #40a070 #34835c 4.62:1
f-string substitution #70a0d0 #3c7ab7 4.51:1
class name #0e84b5 #0d7dac 4.62:1
variable #bb60d5 #af44ce 4.62:1

Those are minimum-change candidates, not a design proposal; a designer may prefer a bigger move on the comment colour in particular, since 4.68:1 is barely over the line.

Options

  1. Fix in both themes, same values, before the cutover. One PR here (styles/quantecon.css, CODE HIGHLIGHTING block, light values only) and one in quantecon-book-theme; refresh the visual baselines in both.
  2. Fix here only and let the Sphinx sites keep the old values until they are retired. Simpler, but the parity tracker (Book-theme parity cutover — tracking #147) would need to record the known difference.
  3. Accept as is. The colours have shipped on every lecture site for years without a reported complaint; record the decision and close.

Where it fits: not a cutover gate (#147 is about matching the current sites, which this does), so deliberately off the parity milestone. The decision should be taken before Phase 6 (#92) writes the parity docs, so the docs describe the settled palette.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

discussOpen-ended team deliberation or a decision to be made

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions