Skip to content

Theme: Improve contrast for brand text, fills, and focus rings - #86614

Merged
ciampo merged 17 commits into
trunkfrom
codex/theme-saturation-focus-contrast
Nov 25, 2026
Merged

ciampo merged 17 commits into
trunkfrom
codex/theme-saturation-focus-contrast

Conversation

@ciampo

@ciampo ciampo commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #86052. Builds on #87174 (WCAG luminance) and #87175 (background and divider saturation), both merged. The List View changes are in #87177, which should merge first. The DatePicker fix shipped in #86809.

What?

Adjust brand text, fills, and focus rings when the chosen theme colors produce too little contrast. In a menu using the Sunrise colors, the keyboard highlight goes from 1.92:1 to 3.77:1 against the popup.

Why?

A menu can use a solid fill as its only keyboard focus indicator. Reporting a warning leaves that highlight hard to see.

How?

The color ramp builder checks brand colors against three neutral backgrounds and the brand background. It targets 3:1 for focus rings and strong fills, and 4.5:1 for brand text. The primary ramp builds its surfaces first, adjusts the fills, focus ring, and text against them, and moves the seed when the text on the fills or the active fill still falls short. If a pair still falls short, onColorWarnings reports it.

The provider keeps the supplied primary seed in --wp-admin-theme-color. With the Sunrise colors, that value stays #ad631e while the resting WPDS brand fill becomes #e79858. Legacy controls and WPDS controls can therefore show different accent colors side by side. Moving those consumers to WPDS tokens removes the mismatch.

Testing Instructions

  1. In Storybook, open Theme Provider → Example Application. In the toolbar choose Theme → Custom and enter background #cc4541 and primary #ad631e.
  2. Inspect the Save button. Its resting fill should be #e79858. The surrounding provider should still expose #ad631e as its legacy admin accent.
  3. Switch to Light and check the default blue selection and button colors.

Testing Instructions for Keyboard

In the @wordpress/ui → Menu → Default story, set the same Sunrise colors. Tab to the trigger, press Enter, and move through the enabled items with the arrow keys. On Archive, the highlight should be #fbaa6b against the #ac1b21 popup (3.77:1).

Screenshots or screencast

Before is the saturation PR (#87175, 56671c7). After is this PR at 7da305e; the current head produces the same colors in these examples, except Custom Charcoal, whose fill is one hex level off. Each Color Scales capture shows the background ramp above the primary ramp. Red outlines mark contrast warnings. In the Example Application, compare the Save button with its header.

Sunrise

Background #cc4541, primary #ad631e. The Save button fill changes from #ad631e to #e79858. Its contrast against the header goes from 1.56:1 to 3.08:1. In the menu, the keyboard highlight on Archive goes from 1.92:1 to 3.77:1 against the popup.

Before After
Sunrise background and primary color ramps before the contrast fix Sunrise background and primary color ramps after the contrast fix
Sunrise Example Application header and Save button before the contrast fix Sunrise Example Application header and Save button after the contrast fix
Sunrise Menu with keyboard focus on Archive before the contrast fix Sunrise Menu with keyboard focus on Archive after the contrast fix
Blue

Background #3876a8, primary #437aa8. The Save button fill changes from #437aa8 to #76afe0. Its contrast against the header goes from 1.57:1 to 3.08:1.

Before After
Blue background and primary color ramps before the contrast fix Blue background and primary color ramps after the contrast fix
Blue Example Application header and Save button before the contrast fix Blue Example Application header and Save button after the contrast fix
Ectoplasm

Background #4f386e, primary #646c3e. The Save button fill changes from #636b3d to #929b6b. Its contrast against the header goes from 1.60:1 to 3.07:1.

Before After
Ectoplasm background and primary color ramps before the contrast fix Ectoplasm background and primary color ramps after the contrast fix
Ectoplasm Example Application header and Save button before the contrast fix Ectoplasm Example Application header and Save button after the contrast fix
Coffee

Background #5b534d, primary #916745. The Save button fill changes from #976d4b to #cea07d. Its contrast against the header goes from 1.58:1 to 3.07:1.

Before After
Coffee background and primary color ramps before the contrast fix Coffee background and primary color ramps after the contrast fix
Coffee Example Application header and Save button before the contrast fix Coffee Example Application header and Save button after the contrast fix
Ocean

Background #5f787f, primary #567958. The Save button fill changes from #5b7e5d to #8eb390. Its contrast against the header goes from 1.57:1 to 3.08:1.

Before After
Ocean background and primary color ramps before the contrast fix Ocean background and primary color ramps after the contrast fix
Ocean Example Application header and Save button before the contrast fix Ocean Example Application header and Save button after the contrast fix
Custom Teal

Background #13a586, primary #3858e9. The Save button fill changes from #3858e9 to #2132c4. Its contrast against the header goes from 2.25:1 to 3.63:1.

Before After
Teal background and primary color ramps before the contrast fix Teal background and primary color ramps after the contrast fix
Teal Example Application header and Save button before the contrast fix Teal Example Application header and Save button after the contrast fix
Custom Charcoal

Background #1e1e1e, primary #3858e9. The Save button fill changes from #3757e8 to #4367f9 (#4468fa in the capture). Its contrast against the header goes from 2.69:1 to 3.32:1. The Save label switches from white to black.

Before After
Charcoal background and primary color ramps before the contrast fix Charcoal background and primary color ramps after the contrast fix
Charcoal Example Application header and Save button before the contrast fix Charcoal Example Application header and Save button after the contrast fix
Comparisons from the original combined PR, before the review changes

In Sunrise, 16 of the 22 primary steps change. The Save button's contrast against the header rises from 1.56:1 to 3.08:1.

Sunrise and Blue get lighter brand fills

Sunrise before and after: the primary ramp and the Save button change from brown to a lighter orange.

Blue before and after: the fill and active fill lighten while the focus token stays the same.

The same blue seed on teal and charcoal

Teal before and after: the Save button and brand text darken. The button label stays light.

Charcoal before and after: the fill gets lighter, the Save label changes from white to black, and the focus token stays the same.

Original ramp comparison

Sunrise and dark-neutral ramps before and after the change

Follow-ups

  • Restore the v2 chrome colors for Sunrise and Blue. Since Theme: Preserve saturation in background surfaces and strokes #87175, their ADMIN_THEME_COLORS backgrounds produce chrome colors that drift from Core's sidebar colors: #99171c instead of #8a312d, and #11507e instead of #245278. Background seeds #933330 and #24567e restore the match and leave the brand colors unchanged.
  • Move the remaining --wp-admin-theme-color and --wp-components-color-* consumers to WPDS tokens, then remove the legacy bridge in use-theme-provider-styles.ts. Until then, legacy and WPDS controls can show different accents on dark backgrounds.
  • Fix the v2 sidebar's Dashboard button label, which uses legacy admin colors (#183ad6, #0096dd) instead of the scheme. This predates this PR.
  • Optional: before moving the seed, check whether a slightly different active fill meets the exact text target. Near the switch between dark and light labels, some seeds move further than needed, for example #ff007a on white.
  • Optional: add a ThemeProvider prop that turns off these adjustments, for custom schemes that intentionally miss the targets.

The admin scheme primaries don't need to change. They already pass on light content, and for most schemes no single color passes on both the dark sidebar and white content.

Use of AI Tools

Codex implemented and tested the changes, captured the Storybook comparisons, and prepared the PR updates. After approval, Claude Code rebased the PR, addressed findings from Codex review passes, and captured the comparison against the approved revision.

@github-actions github-actions Bot added the [Package] Theme /packages/theme label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +1.58 kB (+0.02%)

Total Size: 8.72 MB

📦 View Changed
Filename Size Change
build/scripts/theme/index.min.js 28.8 kB +1.58 kB (+5.82%) 🔍

7bbdb4d Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 4d23149 trunk % Change
timeToFirstByte 38.05 ms +9.72% -3.94% 35.1 ms +13.25% -3.99% 8.4%
largestContentfulPaint 64 ms +9.38% -6.25% 60 ms +10% -6.67% 6.67%
lcpMinusTtfb 26.05 ms +14.2% -9.98% 22.95 ms +12.42% -8.28% 13.51%
wpBeforeTemplate 19.35 ms +15.14% -2.64% 18.4 ms +10.49% -3.26% 5.16%
wpTemplate 15.05 ms +2.92% -4.45% 13.8 ms +6.38% -4.64% 9.06%
wpTotal 34.53 ms +11.18% -3.24% 32.09 ms +14.27% -4.27% 7.6%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 4d23149 trunk % Change
timeToFirstByte 31.2 ms +16.83% -3.85% 29.4 ms +5.44% -1.36% 6.12%
largestContentfulPaint 60 ms +6.67% -6.67% 54 ms +3.7% -3.7% 11.11%
lcpMinusTtfb 26.75 ms +7.66% -2.8% 23.9 ms +11.51% -3.77% 11.92%
wpBeforeTemplate 17.12 ms +17.58% -2.63% 16.24 ms +2.59% -1.11% 5.42%
wpTemplate 11.07 ms +7.68% -5.51% 10.48 ms +1.62% -4.48% 5.63%
wpTotal 28.49 ms +17.06% -4.11% 26.83 ms +4.92% -1.57% 6.19%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 4d23149 trunk % Change
mediaProcessingJpeg 227.71 ms +1.18% -0.83% 227.1 ms +1.17% -2.25% 0.27%
mediaProcessingAvif 3726.3 ms +0.52% -0.3% 3736.91 ms +0.97% -1.45% -0.28%
mediaProcessingJpegToAvif 2564.21 ms +0.71% -0.22% 2634.15 ms +0.28% -1% -2.66%

media-upload

Metric 4d23149 trunk % Change
jpegUploadProcessing 1449.19 ms +1.71% -0.84% 1426.27 ms +0.69% -0.22% 1.61%
pngUploadProcessing 211.32 ms +3.37% -9.59% 189.31 ms +6.29% -4.54% 11.63%
largeJpegUploadProcessing 1437.7 ms +0.48% -0.74% 1417.23 ms +0.88% -0.37% 1.44%
multipleImageUploadProcessing 1475.7 ms +0.72% -0.79% 1453.4 ms +1.81% -0.28% 1.53%

post-editor

Metric 4d23149 trunk % Change
serverResponse 301.24 ms +13.31% -2.94% 320.12 ms +4.2% -8.07% -5.9%
firstPaint 325.62 ms +13.02% -4.39% 346.24 ms +9.68% -5.18% -5.96%
domContentLoaded 651.17 ms +0.75% -1.24% 653.73 ms +2.49% -0.97% -0.39%
loaded 651.98 ms +0.77% -1.24% 654.63 ms +2.47% -0.98% -0.4%
firstContentfulPaint 368.47 ms +0.78% -1.29% 366.38 ms +3.65% -1.99% 0.57%
firstBlock 1740.17 ms +2.83% -0.97% 1780.13 ms +0.95% -1.24% -2.24%
type 15.42 ms +4.28% -8.88% 13.57 ms +4.94% -5.31% 13.63%
typeWithoutInspector 15.07 ms +6.44% -8.03% 14.41 ms +1.11% -10.48% 4.58%
typeWithTopToolbar 19.92 ms +4.92% -4.32% 18.44 ms +7.32% -11.55% 8.03%
typeContainer 6.41 ms +10.61% -9.2% 6.66 ms +4.65% -11.26% -3.75%
focus 83.84 ms +2.83% -1.75% 81.8 ms +4.05% -2.91% 2.49%
firstFocus 208.66 ms +0% -0% 193.82 ms +0% -0% 7.66%
selectAll 292.73 ms +1.74% -1.45% 286.52 ms +0.49% -0.56% 2.17%
undo 25.03 ms +7.79% -4.47% 22.98 ms +8.4% -1.96% 8.92%
listViewOpen 29.79 ms +4.36% -4.4% 31.72 ms +4.45% -10.78% -6.08%
inserterOpen 33.2 ms +6.93% -13.1% 30.22 ms +15.52% -5.03% 9.86%
inserterHover 9.05 ms +5.75% -4.64% 8.99 ms +7.01% -4.45% 0.67%
inserterSearch 7.11 ms +3.94% -6.33% 6.71 ms +2.53% -2.24% 5.96%
loadPatterns 502.94 ms +1.83% -3.34% 503.34 ms +1.8% -2.84% -0.08%
wpTotal 292.59 ms +13.76% -3.01% 311.3 ms +4.38% -8.23% -6.01%
wpMemoryUsage 14.81 MB +0% -0% 14.76 MB +0% -0% 0.33%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 4d23149 trunk % Change
serverResponse 308.79 ms +2.61% -8.7% 316.9 ms +0.94% -8.59% -2.56%
firstPaint 324.48 ms +15.92% -6.23% 347.2 ms +10.75% -10.97% -6.54%
domContentLoaded 661.36 ms +0.43% -1.59% 668.25 ms +2.07% -0.32% -1.03%
loaded 662.09 ms +0.43% -1.57% 669.01 ms +2.07% -0.31% -1.03%
firstContentfulPaint 376.22 ms +0.45% -1.99% 382.82 ms +2.59% -1.99% -1.72%
firstBlock 2025.4 ms +1.78% -1.5% 2034.27 ms +1.44% -0.37% -0.44%
type 14.94 ms +5.49% -7.16% 14.03 ms +6.34% -3.85% 6.49%
navigate 92.7 ms +9.87% -2.56% 99.88 ms +2.17% -7.8% -7.19%
loadPatterns 1118.46 ms +1.32% -8.07% 1028.5 ms +2.15% -14.21% 8.75%
loadPages 993.96 ms +5.83% -8.06% 997.84 ms +4.71% -9.75% -0.39%
wpTotal 300.4 ms +2.71% -8.91% 308.56 ms +0.99% -8.87% -2.64%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

7bbdb4d Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

keeps the default tab when a tab is added before it in /test/e2e/specs/editor/blocks/tabs.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

Expected: 2
Received: 0

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/tabs.spec.js:690:60

7bbdb4d Run

@ciampo
ciampo force-pushed the codex/theme-saturation-focus-contrast branch from 7b6ad05 to 45c34b7 Compare November 13, 2026 09:39
@github-actions github-actions Bot added [Package] Data /packages/data [Tool] WP Scripts /packages/scripts [Package] Components /packages/components [Package] Blocks /packages/blocks [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Notices /packages/notices [Package] Format library /packages/format-library [Tool] ESLint plugin /packages/eslint-plugin [Package] Block editor /packages/block-editor [Package] Edit Post /packages/edit-post [Package] Edit Widgets /packages/edit-widgets [Tool] Env /packages/env [Package] Icons /packages/icons [Tool] stylelint config /packages/stylelint-config [Package] Edit Site /packages/edit-site [Package] Base styles /packages/base-styles [Package] Media Utils /packages/media-utils [Package] Patterns /packages/patterns [Package] DataViews /packages/dataviews [Package] Fields /packages/fields [Package] UI /packages/ui [Package] wp-build /packages/wp-build [Package] Sync /packages/sync [Package] Theme Build Tools [Package] Image Editor Related to packages/image-editor labels Nov 13, 2026
@ciampo

ciampo commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Update: I split the code changes across 4 different PRs:

  1. Theme: Use WCAG luminance coefficients for contrast checks #87174
  2. Theme: Preserve saturation in background surfaces and strokes #87175
  3. List View: Keep selected labels, badges and focus rings readable #87177
  4. This PR, which now focuses on enforcing minimum contrast on brand text, fills, and focus rings

@mirka

mirka commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

I actually checked how far off the primary colors could be, and was relieved to see that there isn't going to be much noticeable change anyway.

Color schemes before/after

Before after of all color schemes Before after of all color schemes, own background

It helps that most of the changes are in dark background, and at least in current Gutenberg the dark background UI is very limited. I think it's mostly under first-party control. So the conclusion here is that I was overestimating the impact. The only risk is probably the foreground text colors flipping, but given the limited amount of dark background UI, we should be able to check them all for any issues.

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I have checked the sidebar UI for any issues, and it seems fine. I found one issue in the experimental sidebar, but that is preexisting.

v2 sidebar with wrong button color

For cases in the future where we want the ability for users to create custom color schemes even if they don't meet accessibility standards, I'm assuming we're going to add a new prop to stop the auto-adjustments.

I think we're good to go 👍

@ciampo

ciampo commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! I'll merge once the rest of the stack / dependent PRs are also merged

Rebase the focus, strong-fill, and text contrast changes onto trunk now
that the WCAG luminance (#87174) and saturated surfaces (#87175) changes
have landed separately.
Check emitted primary colors against the actual contrast targets when
reusing the seed or picking fill text, and keep the closest passing seed
when the search ends on a failing sample.
When a searched primary color falls below its target once serialized,
use the search endpoint if it still meets the actual targets.
Apply the gamut-mapping endpoint only to steps whose search reached its
target, so forced brand surfaces keep their tint. Use the passing seed
sample closest to the supplied seed whenever the search finds one.
The seed search can stop on a passing seed far from the supplied one
when another step's deficit is close to zero there. Bisect between the
supplied seed and the passing sample to keep the closest passing seed.
The primary surfaces keep the lightness pinned from the background ramp,
so build them before the fills and list them as references for the
fills, focus ring, and brand text. This removes the separate brand
surface check. Stop the seed search at its first passing sample and
end the refinement once it reaches the emitted color resolution.
Reference the neutral surface and the public brand surface for the
fills, focus ring, and brand text, instead of every primary surface.
The other surfaces are not checked as pairs, and requiring them moved
seeds that already passed.
Snap primary seed trials to their emitted color so seeds that emit the
same color produce the same ramp. Refine only the steps that failed at
the supplied seed, then check the complete ramp, and refine every step
only if that check fails.
Start the primary seed search from the emitted seed, as its trials do,
so a seed and its hex value produce the same ramp. When gamut mapping
pushes an emitted color below its target, move it toward the endpoint
only as far as needed, keeping its tint.
Seed searches query the gamut's maximum chroma at the same lightness and
hue many times. Cache sRGB results by their exact inputs, capped at
1,000 entries, so ramps stay identical.
@ciampo

ciampo commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I pushed a few changes after the approval, and rebased on trunk now that #87174 and #87175 have landed.

  • The primary ramp now builds its surfaces first and checks the fills, focus ring, and brand text against the neutral surface and the public brand surface. This removed the separate brand-surface check, and most custom colors no longer need a seed search.
  • Seeds that already meet the targets keep their color, for example #5f5f5f on black. Neighboring seeds no longer jump to distant fills: #1d1d1d and #1e1e1e both give #2c2c2c.
  • When gamut mapping pushes a color below its target, the color now moves only as far as needed and keeps its tint.
  • --wp-components-color-accent-inverted now prefers white when white fits the legacy accent, because the darker legacy states only add contrast against white.
  • Ramp generation is faster than in the approved revision. Repeated builds take 3.9 ms instead of 7.9 ms for Modern, and 0.7 ms instead of 6.5 ms for #1e90ff on the default background.

Compared with the approved revision (7da305e), the admin schemes are unchanged on light backgrounds. Five dark-background rows move by one hex level and still meet every target. The v2 sidebar looks the same; only the Modern focus ring changes, from #8eb0ff to #8fb0ff.

I also added a follow-up section to the PR description, which I'm going to tackle soon.

Comparison with the approved revision

The v2 sidebar with keyboard focus on Dashboard, captured at the same density as the approval screenshots. The left and middle columns are those screenshots (trunk at e8fdab7 and this PR at 7da305e). The right column is the current head.

V2 sidebar for Modern, Sunrise, Blue, and Ectoplasm: trunk, the approved PR revision, and the current head. Backgrounds and focus rings match the approved revision except the Modern ring, one hex level lighter.

Brand tokens for each scheme, in the same layout as the approval comparison. The left column is 7da305e and the right column is the current head. Bold underlined values changed.

Brand tokens for each admin scheme on light, dark, and its own background, at the approved revision and the current head. Only five dark-background rows change, each by about one hex level.

@ramonjd

ramonjd commented Nov 30, 2026

Copy link
Copy Markdown
Member

Hi folks!

I noticed with the default Modern admin colour scheme, the primary button now has black text.

Screenshot 2026-11-30 at 12 28 13 pm

I saw it on the styles tab before saving a change - /wp-admin/site-editor.php?p=%2Fstyles - in TT5 and Ipsum.

Is that right?

I took it be a bug (should white text win on brand fills?) but wasn't sure if there was some intention behind it.

@jasmussen

Copy link
Copy Markdown
Contributor

CC: @WordPress/gutenberg-components

@ciampo

ciampo commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

In short, that's not strictly a bug, but the result of the additional (and necessary) contrast constrains that we recently added.

Intuitively, for dark themes, if the provided brand seed color doesn't reach 3:1 contrast against the background seed, the algorithm will lighten it until it does. As the brand color gets lighter, it may reach a point where white text won't have enough contrast against it (especially its hover state, which gets even lighter), causing the algo to choose dark text.

A few thoughts:

  • we already coded a preference in the algorithm for preferring white text whenever it's possible, but that's not always possible
  • we have to follow WCAG contrast rules, which unfortunately don't really match the human eye perception (I think we all agree that white text looks more legible than dark text in that example). Things will get better when WCAG compliance will use APCA contrast, which a lot closer to human perception. Eventually 🤞

Having said all of this, and assuming that showing dark text is not an option we're willing to settle on, I think that the easiest workaround is to tweak the theme seeds (mostly darkening the background seed color) to "make room" for white foreground color when paired on brand background color.

I opened #87673 to implement those changes

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

Labels

[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Theme /packages/theme [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants