You picked a light gray for the secondary text because on white it "looks elegant". People with low vision, or anyone looking at a screen in the sun, cannot read that text. The Web Content Accessibility Guidelines (WCAG) turn this problem into a verifiable number: the contrast ratio. The standard is the W3C's, the criteria can be checked one by one, and some can be calculated with a ten-line program, as you will do shortly.
An estimate by the World Health Organization indicates that about 1.3 billion people, 16% of the world's population, experience significant disability. Not all of them have difficulty with the web, but the figure explains why accessibility is not a niche. Here you find what versions 2.1 and 2.2 of WCAG say, the criteria that weigh most on code, what an automatic check sees and what it does not, and what the official text says about the European legislation that, from 28 June 2025, concerns many digital services.
2.1 or 2.2: which version, today
WCAG 2.0 is a W3C Recommendation of 11 December 2008; WCAG 2.1 was published as a Recommendation in June 2018. Version 2.2 is a W3C Recommendation of 12 December 2024, and it is the one that the "latest version" page of WCAG 2 serves today. The text of WCAG 2.1 that the W3C publishes now carries the date of 6 May 2025. The W3C specifies that 2.2 does not deprecate or supersede 2.0 and 2.1, which remain Recommendations, but advises the use of 2.2 "to maximize future applicability" and adopting it as a target even when formal obligations cite earlier versions.
The title of this series says "2.1 AA", and it remains a sensible target, because many specifications and tender documents still cite that version. Moving to 2.2 is cheap, though: 2.2 is additive, so a site that conforms to 2.2 also conforms to 2.1. The two figures to keep in mind, counted on the official text with a program and not from memory, are these: 2.1 contains 30 level A criteria, 20 level AA and 28 level AAA; 2.2 contains 31, 24 and 31. Aiming for "AA" therefore means 50 criteria in 2.1 and 55 in 2.2.
| New in WCAG 2.2 | Level | What it asks, in short |
|---|---|---|
| 2.4.11 Focus Not Obscured (Minimum) | AA | The component that has keyboard focus is not entirely hidden by other content |
| 2.5.7 Dragging Movements | AA | Actions performed by dragging have an alternative that does not require dragging |
| 2.5.8 Target Size (Minimum) | AA | Pointer targets of at least 24 by 24 CSS pixels, with exceptions |
| 3.2.6 Consistent Help | A | Help mechanisms, when present, appear in the same relative order across the pages of a set |
| 3.3.7 Redundant Entry | A | Information already provided in the same process does not have to be entered again, with exceptions |
| 3.3.8 Accessible Authentication (Minimum) | AA | Authentication does not require a cognitive function test without alternatives |
The table lists the six new level A and AA criteria; 2.2 adds three more at level AAA (2.4.12, 2.4.13, 3.3.9) that are not needed here. The right-hand column is my own summary: the normative text has exceptions that change the verdict, and for an audit you must read the full criterion. Another novelty lies in an absence: criterion 4.1.1 Parsing is marked "Obsolete and removed" in 2.2, so "markup validity" is no longer a criterion to pass in itself, but it still matters for the rest, such as the accessible name of controls.
The four principles and what you do with them
The criteria are organized under four principles, summed up by the acronym POUR. Perceivable: information and user interface components must be presentable to users in ways they can perceive. Operable: user interface components and navigation must be operable. Understandable and robust complete the picture, the latter with the idea that content must be robust enough to be interpreted by a wide variety of user agents, including assistive technologies. Every success criterion belongs to one of these principles.
In daily work the principles are not "implemented": they are translated into checks. Contrast sits under Perceivable (1.4.3, 1.4.11), keyboard and focus under Operable (2.1.1, 2.1.2, 2.4.7), labels under Understandable (3.3.2), the name and role of controls under Robust (4.1.2). The paragraphs that follow take one criterion per principle, and where the criterion can be calculated or checked, I really calculate it and check it.
Perceivable: contrast, calculated
Criterion 1.4.3 (level AA) asks for a contrast ratio of at least 4.5:1 for text, with three exceptions: large text requires 3:1, and the text of inactive components, of pure decoration or of logos has no requirement. "Large text" is text of at least 18 point, or 14 point bold. Criterion 1.4.11 extends the 3:1 minimum to the visual information needed to identify a control and its state, for example a border or a focus indicator.
Where do those numbers come from? The "Understanding" documentation for the criterion explains that 3:1 is the minimum recommended by the ISO 9241-3 and ANSI/HFES 100-1988 standards for standard text and vision, and that 4.5:1 comes from 3 times 1.5, where 1.5 is the loss of contrast sensitivity that, according to an empirical finding cited by the document, accompanies a visual acuity of 20/40. With the same logic the document derives about 7:1 for an acuity of 20/80, a value that appears in criterion 1.4.6 at level AAA. The number is not "magic", but it is a declared compromise.
The definition of the ratio is in the WCAG glossary: (L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter of the colors and L2 that of the darker. Relative luminance is computed from the sRGB channels: each channel is divided by 255, linearized with a two-branch formula (threshold 0.04045) and combined with the weights 0.2126, 0.7152 and 0.0722. The module below is the literal translation. The lines that matter are linear, which implements the two branches, and contrastRatio, which always puts the lighter color in the numerator, so that the order between text and background does not change the result.
// Contrast ratio according to the WCAG 2.2 definition (sRGB, threshold 0.04045).
export function parseHex(hex) {
const m = /^#([0-9a-f]{6})$/i.exec(hex);
if (!m) throw new Error(`invalid color: ${hex} (expected #rrggbb)`);
const n = parseInt(m[1], 16);
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
}
function linear(channel8bit) {
const s = channel8bit / 255;
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
}
export function luminance(hex) {
const [r, g, b] = parseHex(hex).map(linear);
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
export function contrastRatio(fg, bg) {
const [a, b] = [luminance(fg), luminance(bg)];
const [light, dark] = a >= b ? [a, b] : [b, a];
return (light + 0.05) / (dark + 0.05);
}
// The value is NOT rounded before the comparison (Understanding SC 1.4.3).
export function passes(ratio, threshold) {
return ratio >= threshold;
}
The final comparison, in passes, has no rounding, because the Understanding documentation says that calculated values must not be rounded: 4.499:1 does not meet the 4.5:1 minimum. The next program applies it to four pairs of colors. Note that black on white gives 21:1, the maximum possible, and that white on white gives 1:1, the minimum.
import { contrastRatio, passes } from './contrast.mjs';
const pairs = [
['#000000', '#ffffff'],
['#ffffff', '#ffffff'],
['#767676', '#ffffff'],
['#777777', '#ffffff'],
];
for (const [fg, bg] of pairs) {
const r = contrastRatio(fg, bg);
console.log(`${fg} on ${bg}: ${r.toFixed(4)}:1 normal text AA (4.5): ${passes(r, 4.5) ? 'passes' : 'FAILS'}`);
}
// Look for a gray on white whose ratio shown to two decimals is 4.50 but is < 4.5
for (let v = 0; v < 256; v++) {
const hex = '#' + v.toString(16).padStart(2, '0').repeat(3);
const r = contrastRatio(hex, '#ffffff');
if (r < 4.5 && r.toFixed(2) === '4.50') {
console.log(`${hex} on #ffffff: ${r.toFixed(6)} (rounded: ${r.toFixed(2)}) -> ${passes(r, 4.5) ? 'passes' : 'FAILS'}`);
}
}
// Output:
// #000000 on #ffffff: 21.0000:1 normal text AA (4.5): passes
// #ffffff on #ffffff: 1.0000:1 normal text AA (4.5): FAILS
// #767676 on #ffffff: 4.5422:1 normal text AA (4.5): passes
// #777777 on #ffffff: 4.4781:1 normal text AA (4.5): FAILS
The gray #767676 on white passes the threshold by a hair (4.5422:1), while #777777, which looks identical to the eye, does not reach it (4.4781:1). To verify the function I compared the results with two other independent implementations: a Python implementation written for the purpose and the internal contrast function of axe-core 4.14.0. On these five pairs the three give the same values down to the sixth decimal place. This proves that the formula was translated correctly, not that the chosen colors are legible to everyone: for that you need people.
The border case remains. The next program scans the blues of the form #0b??ff on a white background and stops at the first one whose ratio, rounded to two decimals, shows 4.50 although it is below the threshold. It is an example of how a tool that rounds can give a different verdict from the criterion.
import { contrastRatio } from './contrast.mjs';
// Scan of the blues on white: first color #0bxxFF... with a displayed ratio of 4.50 but below the threshold
const hex = (r, g, b) => '#' + [r, g, b].map((v) => v.toString(16).padStart(2, '0')).join('');
for (let b = 255; b >= 0; b--) {
for (let g = 0; g < 256; g++) {
const c = hex(0x0b, g, b);
const r = contrastRatio(c, '#ffffff');
if (r < 4.5 && r.toFixed(2) === '4.50') {
console.log(`${c} on #ffffff: ${r.toFixed(6)} (to two decimals: ${r.toFixed(2)}) -> below 4.5, FAILS`);
process.exit(0);
}
}
}
console.log('no case found');
// Output:
// #0b6ffa on #ffffff: 4.498300 (to two decimals: 4.50) -> below 4.5, FAILS
A color that your design tool displays as "4.50" may therefore fail. If your contrast gate uses toFixed(1) or compares two decimal digits, the test can approve what the criterion rejects; always compare the full value against the threshold. The confidence is limited to this: the program only computes pairs of opaque colors in #rrggbb format, without transparency, images or gradients, where contrast has to be measured point by point.
Operable: keyboard and focus
Criterion 2.1.1 (level A) asks that all functionality be operable through a keyboard interface, without requiring specific timings for individual keystrokes, except where the underlying function requires input that depends on the path of the user's movement. Criterion 2.1.2 (level A) is "no keyboard trap": if keyboard focus can be moved into a component, it must be possible to move it away, and if this requires more than the unmodified arrow or tab keys the user must be advised. A modal dialog that does not close with Esc or does not release focus is the classic example.
Criterion 2.4.7 (level AA) says that any keyboard operable interface has a mode of operation where the keyboard focus indicator is visible. Removing the outline without replacing it violates it. The Understanding documentation of 1.4.11 adds that the indicator must be contrasted enough: even a button with no visible border needs a focus indication with sufficient contrast. The fragment uses :focus-visible, which shows the indicator to those who navigate by keyboard, and the color #0b5cad, which on white gives 6.67:1 with the same contrastRatio as before.
:focus-visible {
outline: 3px solid #0b5cad;
outline-offset: 2px;
}
This CSS is a pattern to adapt, not run: evaluating a focus indicator requires a browser and, in a real case, the contrast against all the backgrounds on which the component can appear. With 2.2 two further constraints come into play: focus must not stay entirely hidden, for example by a fixed header (2.4.11), and pointer targets must measure at least 24 by 24 CSS pixels, with exceptions (2.5.8).
Understandable and robust: labels, names and roles
Criterion 3.3.2 (level A) asks that when content requires user input, labels or instructions be provided. The Understanding documentation admits that in some cases, for example a single field whose purpose is clear from the context, the visible label may not be needed, and observes that a placeholder hint, when visible, can help. The practical rule I draw from it is a different one: an explicit label costs one line and works in every case, while the placeholder disappears as soon as the user types.
Criterion 4.1.2 (level A) concerns the name, role and value of components, and 1.1.1 (level A) text alternatives: a purely decorative image must be implemented so that assistive technologies can ignore it. For the role, the "first rule of ARIA" from the W3C document Using ARIA applies: if you can use a native HTML element with the semantics and behavior you require already built in, do so, instead of re-purposing another element with an ARIA role. A <button> already has the role, keyboard focus and activation with Enter and Space; a <div role="button"> forces you to rewrite everything. A note of transparency: the document is currently classified by the W3C as a "Discontinued Draft" (24 February 2026), so it is not a standard, but the principle remains the one the W3C publishes for authors.
What an automatic check sees
The test below is on a test HTML file, written by me to have four known defects: an image without alt, a field without a label and with only a placeholder, a button with a single icon and no text, a page with neither language nor title. It is not a file of the site and not a page on the web.
<!doctype html>
<html>
<head><meta charset="utf-8"></head>
<body>
<main>
<img src="dog.jpg">
<form>
<input type="email" placeholder="Email">
<button><svg width="16" height="16"></svg></button>
</form>
</main>
</body>
</html>
The script loads the file into jsdom, injects axe-core 4.14.0 and runs five rules, all limited to what works without the browser's layout. The color contrast rule, for example, was not run: axe needs to compute the real styles, which jsdom does not do. The script also prints the checks that made the label rule pass, and runs on two files: the defective page and a corrected version, with alt, lang, title, explicit label and text in the button.
import { readFileSync } from 'node:fs';
import axe from 'axe-core';
import { JSDOM } from 'jsdom';
async function audit(file) {
const dom = new JSDOM(readFileSync(file, 'utf8'), { runScripts: 'outside-only' });
dom.window.eval(axe.source);
const result = await dom.window.axe.run(dom.window.document, {
runOnly: { type: 'rule', values: ['image-alt', 'label', 'button-name', 'html-has-lang', 'document-title'] },
});
console.log(`${file}: ${result.violations.length} violations`);
for (const v of result.violations) {
console.log(` violated: ${v.id} on ${v.nodes.length} node(s)`);
}
for (const p of result.passes.filter((r) => r.id === 'label')) {
for (const n of p.nodes) console.log(` passed: label, thanks to ${n.any.map((c) => c.id).join(',')}`);
}
}
for (const f of process.argv.slice(2)) await audit(f);
// Output:
// broken.html: 4 violations
// violated: button-name on 1 node(s)
// violated: document-title on 1 node(s)
// violated: html-has-lang on 1 node(s)
// violated: image-alt on 1 node(s)
// passed: label, thanks to non-empty-placeholder
// fixed.html: 0 violations
// passed: label, thanks to explicit-label,non-empty-placeholder
The four violations are exactly the expected ones, and the corrected page has zero. The datum that matters is the last line of the defective page: the field with only the placeholder passes the label rule, because axe accepts a non-empty placeholder as an accessible name. An automatic check that says "all good" does not prove that the page works for someone using a screen reader: it proves that a set of mechanical rules found no defects. The rest you look for by navigating with the keyboard and, when you can, with assistive technologies and with people who use them. The site's WCAG/AgID checker, among the business tools, is one way to do a first check.
What the law says, in the official text
This section reports what I read in the official texts and is not legal advice: for your specific case, consult a professional. Directive (EU) 2019/882 on the accessibility requirements for products and services is dated 17 April 2019 and was published in the Official Journal of the European Union on 7 June 2019. Article 31 establishes that Member States adopt and publish the necessary measures by 28 June 2022 and apply them from 28 June 2025.
Among the services within the scope, Article 2 lists, for consumers, electronic communications services, services providing access to audiovisual media services, certain elements of passenger transport services (websites, mobile device-based services including mobile applications, electronic tickets and electronic ticketing services, delivery of transport service information, interactive self-service terminals), consumer banking services, e-books and dedicated software, and e-commerce services. Article 4(5) states that microenterprises providing services shall be exempt from complying with the accessibility requirements referred to in paragraph 3 of that Article and any obligations relating to the compliance with those requirements. The directive does not name the WCAG: it speaks of accessibility requirements and harmonised standards, and which version of the WCAG is referenced by the harmonised standards I did not verify.
In Italy the directive was transposed by the decreto legislativo 27 maggio 2022, n. 82 (Legislative Decree no. 82 of 27 May 2022), published in the Gazzetta Ufficiale (Italy's official gazette) no. 152 of 1 July 2022 and in force from 16 July 2022. Article 1 establishes that the decree sets the requirements for products and services placed on the market from 28 June 2025 and restates the directive's list of services. The legge 9 gennaio 2004, n. 4 (Law no. 4 of 9 January 2004, the "Stanca law"), published in the Gazzetta Ufficiale no. 13 of 17 January 2004, is titled as the provisions to support the access of disabled people to information technology tools. I did not verify the current text of the Stanca law, and in particular the thresholds concerning private entities: I do not report them.
Frequently asked questions
Should I aim for WCAG 2.1 AA or 2.2 AA?
The W3C recommends adopting 2.2 as a target even when formal obligations cite earlier versions, because 2.2 is additive: what conforms to 2.2 conforms to 2.1. If a tender document cites 2.1, your conformance is measured against 2.1; building for 2.2 already adds six level A and AA criteria.
Is an automatic check enough to say that the site is accessible?
No. In the test above, axe-core 4.14.0 found four defects out of the four expected, but it also let a field with only the placeholder pass. An automatic check reports a part of the problems and must be completed with a keyboard test, with assistive technologies and with people who use them.
Does the minimum contrast also apply to buttons and icons?
Criterion 1.4.3 concerns text and images of text. For the visual information needed to identify a control and its state, such as borders and focus indicators, criterion 1.4.11 asks for at least 3:1 against adjacent colors.
What you can do now
You can say which version of WCAG is the current Recommendation and why it pays to look at 2.2 even with a "2.1 AA" target. You can compute the contrast ratio with the official formula and you know that the comparison with the threshold must not be rounded. You know which criteria touch keyboard, focus, labels and accessible names, you have seen what an automatic check reports and what it lets through, and you have drawn from the official texts what is in force and from 28 June 2025. To try it, run an axe check on a static test page of your own and then navigate the same page using only Tab, Enter and Esc.
The neighboring articles in the series are Nielsen's heuristics (number 3 on the emergency exit ties in with criterion 2.1.2) and the design system with tokens, where contrast becomes an automatic check on colors. The index is on the series page.
Later in the series you will also find prototyping from design to code and usability testing with think-aloud and A/B.
Sources
- W3C, Web Content Accessibility Guidelines (WCAG) 2.2 - Recommendation status (12 December 2024), advice to adopt 2.2, new criteria and levels, definition of contrast ratio and relative luminance, text of criteria 1.4.3, 2.1.1, 2.1.2, 2.4.7, 2.5.8; criteria counts obtained by analyzing the text, consulted on 2026-11-13
- W3C, Web Content Accessibility Guidelines (WCAG) 2.1 - text published with the date of 6 May 2025, counts of 30/20/28 by level, consulted on 2026-11-13
- W3C WAI, Understanding Success Criterion 1.4.3: Contrast (Minimum) - rationale for the 3:1, 4.5:1 and 7:1 ratios, no rounding, consulted on 2026-11-13
- W3C WAI, Understanding Success Criterion 1.4.11: Non-text Contrast - 3:1 for controls and states, focus indication, consulted on 2026-11-13
- W3C WAI, Understanding Success Criterion 3.3.2: Labels or Instructions - cases in which the visible label may not be needed, consulted on 2026-11-13
- W3C, Using ARIA - first rule of ARIA; document with "Discontinued Draft" status, consulted on 2026-11-13
- EUR-Lex, Directive (EU) 2019/882, English text - dates, Articles 2, 4 and 31; read in the parts cited, consulted on 2026-11-13
- Normattiva, decreto legislativo 27 maggio 2022, n. 82 (Italian text; Legislative Decree no. 82 of 27 May 2022) - publication details and Article 1, read in the parts cited, consulted on 2026-11-13
- Gazzetta Ufficiale, legge 9 gennaio 2004, n. 4 (Italian text; Law no. 4 of 9 January 2004) - title and publication details; the current text was not read, consulted on 2026-11-13
- World Health Organization, Disability - estimate of 1.3 billion people, 16%, consulted on 2026-11-13
- Measurements made by me: the listings in the article, run with Node 24.11 and axe-core 4.14.0 in jsdom 29.1.1 on test HTML files; comparison with an independent Python implementation
Commenti
Caricamento commenti...
Sign in to comment