question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Theme accessibility

See original GitHub issue

Web accessibility is very important. For a syntax highlighting library this is particularly relevant when it’s used for a website that is meant to be used by many users, some of whom may not have perfect vision and struggle to read code highlighted with themes that have a low contrast. The WCAG web accessibility standard defines the following AA success criteria:

The visual presentation of text and images of text has a contrast ratio of at least 4.5:1

Currently highlight.js already comes with several themes that meet this criteria. However most themes that come with highlight.js do not meet WCAG AA. I don’t think that this is a problem per se, since highlight.js might be used just for e.g. just a personal application where the user chooses can choose their own color theme as they wish.

I do however think that highlight.js should address two things:

  • If highlight.js comes with themes that do not meet WCAG AA, the Demo should raise awareness about which themes have a high contrast and which themes don’t. This could be as simple as dividing the themes list in Themes with high contrast, Themes with lower contrast and linking some informative web page that explains when/why this matters.

  • I find it problematic that the Default theme does not meet WCAG AA. I think either it’s colors should be changed to meet WCAG AA or it should be renamed to something else (maybe Legacy Default). This is important because accessibility by default is important. (And also because the README currently suggests using default.css).

To get this started I opened the pull request #3390 which calculates the minimum WCAG contrasts for each theme and asserts that they are the same as defined in test/contrast/min_contrasts.json. (Contrasts can still be decreased but not accidentally).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:23 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
not-my-profilecommented, Dec 31, 2021

Seeing that https://highlightjs.org/ still does not raise awareness about accessibility, maybe you can take some inspiration from https://pygments.org/ for which I have since implemented such changes.

  • https://pygments.org/styles/ now lists styles with a good contrast first and styles with a lower contrast only after the paragraph:

    The following styles do not meet the WCAG 2.1 AA contrast minimum, so they might be difficult to read for people with suboptimal vision. If you want your highlighted code to be well readable for other people, you should use one of the earlier styles instead.

  • https://pygments.org/demo/ separates the styles in the <select> into two <optgroup> (good contrast & suboptimal contrast) and selecting a style with a suboptimal contrast shows the warning “style may have poor contrast”.

1reaction
joshgoebelcommented, Nov 7, 2021

I feel like that only works if they are collapsible or we have some sort of table of contents. Or maybe I’m just imagining what the UI would look like. It would have to be clear that if you scroll they were dark themes below. 

That doesn’t necessarily solve the badge floating onto the next line problem. You could solve that with a nonbreaking space but then you might end up where the badges are so far to the right that they can’t be seen at all. 

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 7 Best Accessible WordPress Themes (WCAG 2.1 AA)
Accessible WordPress themes · 1. Period by Compete Themes · 2. Founder by Compete Themes · 3. Morning by Compete Themes · 4....
Read more >
Accessibility | Theme Developer Handbook
A WordPress theme should generate pages that everyone can use — including those who cannot see or use a mouse. The default WordPress...
Read more >
18 Best Accessible WordPress Themes (2022) - Colorlib
Best-Performing Accessible WordPress Themes · 1. Polyclinic · 2. Icelander · 3. Monument Valley · 4. Cindy · 5. Angelica · 6. Björk...
Read more >
Accessibility for themes - Shopify Help Center
Learn how to use your theme to keep your online store accessible to everyone.
Read more >
Accessibility Ready WordPress Themes
Adheres to accessibility best practices like color contrast, keyboard navigation, and form/link focus.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found