Skip to content

fix(button): increase contrast#666

Merged
LeoMcA merged 10 commits into
mainfrom
653-increase-positive-button-contrast
May 26, 2026
Merged

fix(button): increase contrast#666
LeoMcA merged 10 commits into
mainfrom
653-increase-positive-button-contrast

Conversation

@caugner
Copy link
Copy Markdown
Contributor

@caugner caugner commented Aug 29, 2025

Description

Increases the contrast between the background color with/without hover, all while ensuring a visible hover effect.

Motivation

Resolve accessibility issues.

Additional details

As of 120d223:

WCAG contrast ratios

State Light (main → branch) Dark (main → branch)
YES default (no hover) 3.81:1 🔴 → 7.74:1 🟢 10.49:1 🟢
YES hover 3.66:1 🔴 → 7.44:1 🟢 9.56:1 🟢 → 5.54:1 🟠
NO default (no hover) 5.02:1 🟠 6.35:1 🟠
NO hover 4.53:1 🟠 → 5.67:1 🟠 6.24:1 🟠

Legend: 🔴 fails AA (<4.5:1) · 🟠 passes AA (≥4.5:1) · 🟢 passes AAA (≥7:1) — thresholds for normal text.

Screenshots

Before After
Light Yes image image
Light No image image
Dark Yes image image
Dark No image image

Related issues and pull requests

Fixes #653.

Only secondary/plain, as primary uses white text color.
@caugner caugner requested a review from a team as a code owner August 29, 2025 11:58
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 29, 2025

82f3524 was deployed to: https://fred-pr666.review.mdn.allizom.net/

@caugner caugner changed the title fix(button): increase contrast for light positive action fix(button): increase contrast for light action buttons Aug 29, 2025
@caugner caugner marked this pull request as draft August 29, 2025 12:05
@caugner caugner marked this pull request as ready for review August 29, 2025 12:13
@OnkarRuikar
Copy link
Copy Markdown
Contributor

Please update the plain button hover contrast in dark mode as well:

 /* Plain */
  &[data-variant="plain"] {
    &:hover {
--      background-color: light-dark(var(--color-gray-80), var(--color-gray-20));
++      background-color: light-dark(var(--color-gray-80), var(--color-gray-40));
    }

The current hover is almost not noticeable. In the following video, the Clear button has the above change:

button_contrast-2025-08-31_11.06.45.mp4

In the above video, the buttons are zoomed in, but in the normal case hover color change is not visible.

@caugner caugner requested a review from LeoMcA September 1, 2025 12:50
@caugner
Copy link
Copy Markdown
Contributor Author

caugner commented Sep 1, 2025

Please update the plain button hover contrast in dark mode as well:

 /* Plain */
  &[data-variant="plain"] {
    &:hover {
--      background-color: light-dark(var(--color-gray-80), var(--color-gray-20));
++      background-color: light-dark(var(--color-gray-80), var(--color-gray-40));
    }

The suggestion passes WCAG AAA: 7.14:1 7.39:1

@mdn/content-team Do you approve the changes in this PR, and/or Onkar's suggestion?

@caugner caugner added the needs content decision This issue needs a decision from the MDN Content Team before it can proceed. label Sep 1, 2025
@Rumyra
Copy link
Copy Markdown
Contributor

Rumyra commented Sep 2, 2025

Yes approve both 👍

@caugner
Copy link
Copy Markdown
Contributor Author

caugner commented Sep 3, 2025

I looked into applying @OnkarRuikar's suggestion, but noticed that all neutral dark variants have similar contrast issues, see the following screenshots, with hover on the middle button:

image image image image

Here's how these would look with increased contrast (1120399):

image image image image

@Rumyra Does that look right?

Edit: Contrast ratios are 12.35:1 and 7.39:1 respectively, both passing WCAG AAA.

@OnkarRuikar
Copy link
Copy Markdown
Contributor

@caugner thanks for increasing the scope of the fix. The dark theme is looking good.

img
In the Light theme could you increase darkness a bit more? I am using a LED screen and the hovered unhovered difference is not that stark.

@caugner
Copy link
Copy Markdown
Contributor Author

caugner commented Sep 3, 2025

In the Light theme could you increase darkness a bit more?

I assume you're referring to this one:

image

Here's how this looks with increased "hover contrast" (34c264c):

image

Contrast is 7.39:1 (previously 13.25:1), still passing WCAG AAA.

@caugner caugner changed the title fix(button): increase contrast for light action buttons fix(button): increase hover contrast Sep 3, 2025
@caugner
Copy link
Copy Markdown
Contributor Author

caugner commented Sep 3, 2025

I'm thinking that we shouldn't mix these changes up in a single PR:

  • The original changes are increasing contrast between text and background color.
  • The other changes are decreasing contrast between text and background color, to increase contrast between background color with/without hover.

@OnkarRuikar
Copy link
Copy Markdown
Contributor

OnkarRuikar commented Sep 3, 2025

There are other places that could use more hover contrast:

hoverContrast.mp4

Also include the search box suggestion list and left sidebar list. In right sidebar in-viewport items could use more prominent blue background.

@caugner caugner marked this pull request as draft September 3, 2025 13:52
@globau globau removed the needs content decision This issue needs a decision from the MDN Content Team before it can proceed. label Sep 10, 2025
@caugner caugner marked this pull request as ready for review May 25, 2026 14:47
@caugner caugner requested a review from a team as a code owner May 25, 2026 14:47
@caugner caugner marked this pull request as draft May 25, 2026 14:47
caugner added 2 commits May 25, 2026 18:08
Use `--color-green-20` as the default text color for `secondary` and
`plain` positive buttons in light mode, lifting contrast on
`--color-background-primary` from 3.81:1 (fails AA) to 7.74:1 (AAA).
With the default color now matching the previous hover color, the
hover `color` override is redundant and removed.
Use `--color-green-20` instead of `--color-green-10` as the dark-mode
hover background for `secondary` and `plain` positive buttons. The
previous `green-10` is darker than the page background (`gray-10`),
making the hover state effectively invisible (1.10:1 luminance
contrast vs page). `green-20` lifts that to 1.90:1 — still below the
WCAG 1.4.11 3:1 threshold but materially more visible. Text contrast
on the new hover background remains AA (5.54:1).
@caugner caugner marked this pull request as ready for review May 25, 2026 16:49
caugner added 2 commits May 25, 2026 21:18
Avoid shadowing the outer `disabled` array declared at the top of the
render function.
`disabled` is a non-standard attribute on `<a>`, so rendering a separate
disabled-anchor section duplicates the non-disabled one visually while
labeling both as `<a>`.
@caugner caugner changed the title fix(button): increase hover contrast fix(button): increase contrast May 25, 2026
Copy link
Copy Markdown
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

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

Nice!

@LeoMcA LeoMcA merged commit 60f3f48 into main May 26, 2026
13 checks passed
@LeoMcA LeoMcA deleted the 653-increase-positive-button-contrast branch May 26, 2026 11:34
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.

Insufficient color contrast in footer

6 participants