Repository navigation
Revealjs line highlighting cannot meet WCAG contrast #14959
Description
In revealjs, code-line-numbers highlights lines by fading the other lines to opacity: 0.4 (line-highlight.css#L1-L7). The design comes from the reveal.js highlight plugin, which uses the same value.
At 0.4, the faded lines fail WCAG 1.4.3 Contrast (Minimum). With the default highlight theme on a white background, faded tokens are 1.7:1 to 2.6:1. The requirement is 4.5:1.
No other opacity value is a good fix. The token colors of the theme are close to 4.5:1 at full opacity, so they have almost no room to fade:
| Token | Color | Contrast at 1.0 | Contrast at 0.4 | Minimum opacity for 4.5:1 |
|---|---|---|---|---|
attribute (.at) |
#657422 | 5.15 | 1.74 | 0.94 |
import (.im) |
#00769e | 5.14 | 1.81 | 0.93 |
comment (.co) |
#5e5e5e | 6.48 | 1.85 | 0.85 |
| plain text | #111111 | 18.88 | 2.62 | 0.58 |
At 0.94, the highlighted line looks the same as the other lines. The feature then has no function.
The faded text is not exempt. WCAG gives an exemption only for "incidental" text, and the faded lines are content that the audience reads for context. Sometimes an earlier step shows all the lines at full opacity (code-line-numbers="|2|4-5"). This does not help a person in the audience, because that person cannot go back to the earlier step.
Suggestions
- Documentation: In the Line Highlighting section, tell authors that the fade does not meet WCAG contrast. Tell authors who need accessible slides not to use
code-line-numbersfor this purpose. - Investigate other methods: Show emphasis on the highlighted lines and keep the other lines at full contrast. Some possible methods are a background color, a left border, or a bold font weight. A method that uses only color must also meet 1.4.11 Non-text Contrast and 1.4.1 Use of Color. This can be a new default or an option.
Repro
---
format: revealjs
---
## Python
```{.python code-line-numbers="2|4-5"}
import numpy as np # a comment
x = np.linspace(0, 10, 100)
def f(x, k=2):
"""Docstring here."""
return x ** k + 3.5
```Quarto 1.11.4, default revealjs theme. The contrast values come from the computed styles in Chrome.
AI tools helped with this investigation. The investigation used a local clone of quarto-cli (see "Using AI tools to investigate" in CONTRIBUTING.md).
Activity
mcanouil commentedon Oct 26, 2026
While fixing the code annotation line highlight in #13429, I found the same contrast limit in HTML output.
When a code annotation is selected,
htmlanddashboarddraw a translucent band (#aaaaaa22) over the annotated lines.In the light
arrowtheme, the.imimport tokens are#00769eon a#f2f3f5code background, which is 4.63:1.Under the band the background becomes
#e8e9eb, and axe-core reports 4.23:1 for.imtokens on the annotated line, against the 4.5:1 required by WCAG 1.4.3.The dark theme passes.
As in Reveal.js, the token colours have almost no room to spare.
Any tint that darkens the background lowers the contrast, and a tint light enough to pass (
#aaaaaa08gives 4.54:1) is nearly invisible.A different emphasis would avoid the problem, such as a border only, a left rule, or a band behind the text with its own contrast check.
This predates #13429, which only fixes the band's position.
That pull request skips the light-theme contrast test and notes the gap, so a fix here can and should switch it back on if merged.
fix: account for container scroll when placing the code annotation hi…