Skip to content

fix: a11y low contrast in dark mode for code [AC-4348]#5777

Open
Stefan3002 wants to merge 1 commit intocanonical:mainfrom
Stefan3002:fix-a11y-low-contrast-code
Open

fix: a11y low contrast in dark mode for code [AC-4348]#5777
Stefan3002 wants to merge 1 commit intocanonical:mainfrom
Stefan3002:fix-a11y-low-contrast-code

Conversation

@Stefan3002
Copy link
Copy Markdown

@Stefan3002 Stefan3002 commented Mar 19, 2026

Done

  • Increased the contrast for the code element in dark mode.
  • Screenshots show it was too low.
  • The contrast is 5.13 now.

QA

  • Open demo
  • [Add QA steps]
  • Review updated documentation:
    • [List any updated documentation for review]
      Look at a confirmation modal that says: Next time press SHIFT, the contrast of the SHIFT text should be increased and pass a11y guidelines

Check if PR is ready for release

If this PR contains Vanilla SCSS or macro code changes, it should contain the following changes to make sure it's ready for the release:

  • PR should have one of the following labels to automatically categorise it in release notes:
    • Feature 🎁, Breaking Change 💣, Bug 🐛, Documentation 📝, Maintenance 🔨.
  • Vanilla version in package.json should be updated relative to the most recent release, following semver convention
    • if existing APIs (CSS classes & macro APIs) are not changed it can be a bugfix release (x.x.X)
    • if existing APIs (CSS classes & macro APIs) are changed/added/removed it should be a minor version (x.X.0)
    • see the wiki for more details
  • Any changes to component class names (new patterns, variants, removed or added features) or macros should be listed on the what's new page.

Fixes: AC-4348

Screenshots

image

@webteam-app
Copy link
Copy Markdown

@Stefan3002 Stefan3002 changed the title fix a11y low contrast in dark mode for code fix: a11y low contrast in dark mode for code Mar 19, 2026
@Stefan3002 Stefan3002 changed the title fix: a11y low contrast in dark mode for code fix: a11y low contrast in dark mode for code [AC-4348] Mar 19, 2026
@jmuzina jmuzina self-requested a review March 19, 2026 15:27
$color-label-validated: #006b75;
$color-code-background: rgba($color-x-dark, 0.03);
$color-code-background-dark: rgba($color-x-light, 0.3);
$color-code-background-dark: rgba($color-x-light, 0.1);
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.

While indeed the code text now has greater contrast against its own background, this also decreases the contrast between code and non-code text - it seems quite a bit harder to distinguish them.

Before

Image

After

Image

@juanruitina does this new background color look OK to you?

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.

It is more important to be able to read the text than to tell the semantics apart (and in this case, semantics are even reinforced by the monospace font). The contrast lower than 4.5 is not acceptable.

That said, @Stefan3002 it seems the case you are sharing in your screenshot is a corner case caused by the use of muted text. rgba($color-x-light, 0.15) would be sufficient to make the contrast greater than 4.5, see below. We could apply this to code tags only inside muted text, or for all code for the sake of simplicity and increased text contrast in all cases. Both options would be compliant.

image

Interestingly, this is not an issue in the light theme:

image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Indeed, the problem is only present in dark mode 😄

@Stefan3002 Stefan3002 force-pushed the fix-a11y-low-contrast-code branch from fd1412b to 996a28e Compare April 1, 2026 12:26
@Stefan3002
Copy link
Copy Markdown
Author

Hey all, sorry for the huge delay. I was in medical leave unfortunately.

Could I get another review on this please? 😄

@Stefan3002 Stefan3002 force-pushed the fix-a11y-low-contrast-code branch from 996a28e to 86eb229 Compare April 1, 2026 12:32
@jmuzina
Copy link
Copy Markdown
Member

jmuzina commented Apr 2, 2026

No worries, apologies for the delay also, I was on sick leave!

I'll give it a look tomorrow :)

{
"name": "vanilla-framework",
"version": "4.47.0",
"version": "4.47.1",
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.

4.47.0 hasn't been released yet - so doing this would actually skip 4.47.0 in the release order.

I'd recommend to keep this as 4.47.0

Suggested change
"version": "4.47.1",
"version": "4.47.0",

Comment on lines +5 to +7
code {
background-color: rgba($color-x-light, 0.15);
}
Copy link
Copy Markdown
Member

@jmuzina jmuzina Apr 3, 2026

Choose a reason for hiding this comment

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

This should be applied inside %muted-text placeholder, not the muted text class selector, so it applies to elements that extend %muted-text but don't have u-text--muted class (currently only notification timestamps).

@extend %muted-text;

code {
background-color: rgba($color-x-light, 0.15);
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.

$color-x-light is not color-theme sensitive. So, If you test this on light theme, the code background becomes indistinguishable from the background.

Image

To solve this we'd need an opinion from design on what the right background color is for code inside muted text on light mode. But, @juanruitina mentioned this is fine, so I'm OK to leave this mostly as-is, but we should add a comment here explaining why we are using a non-themable variable here.

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.

Little misunderstanding. The quick fix I suggest is to apply the subtlier background of rgba(255, 255, 255, 0.15) to code blocks in the dark theme, regardless of muted or not. I think the proposed code instead targets muted code regardless of theme, resulting in a regression in the light theme.

For the record, I think I was looking at the live version, where there is such a distinction because of the use of var(--vf-color-background-code), rgba(0, 0, 0, 0.03 and should remain unchanged:

Screenshot From 2026-04-06 10-14-46

This is what it looks like in the demo (which is a regression):

Screenshot From 2026-04-06 10-14-52

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.

This PR produces no visual diffs because Vanilla has no examples that use code inside of muted text (I don't think Vanilla was aware of this as a use case). Could you add an example for Code that shows it inside an element with muted text? That way we can capture visual regressions of this use case in future.

It doesn't need to be shown on the docs page - just adding it to examples/ and the combined.html example for Code will cause it to be visually tested.

Comment on lines +4 to +5

code {
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.

Explicitly targeting element tags causes a stylelint error (we try not to apply styles to tags unless we absolutely have to).

I think this is a valid use case for a tag selector though. To ignore the error and pass CI, see one of these examples to temporarily disable (then re-enable) this rule.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants