{"skills":[{"name":"Measure text contrast against its background","description":"Calculate text contrast with the WCAG relative luminance formula and apply the size-specific threshold before rounding the result.","content":"# Measure text contrast against its background\n\nCalculate text contrast with the WCAG relative luminance formula and apply the size-specific threshold before rounding the result.\n\n## When to use this skill\n\n- Someone gives hex or RGB colours for text and background and asks whether they pass WCAG AA.\n- A design review needs to know whether grey body text, link colours, placeholder text or button labels are readable enough.\n- Text sits over a photo, gradient or semi-transparent overlay and the team wants to know whether it passes.\n\n## When not to use it\n\n- Contrast of icons, focus indicators, chart lines or input borders. Those fall under WCAG 1.4.11 Non-text Contrast (3:1 against adjacent colours), a different check.\n- Enhanced contrast at AAA (WCAG 1.4.6: 7:1, or 4.5:1 for large text) unless the person asks for that level.\n- Judging whether a particular person with low vision can read the text. The ratio is a minimum; some people also need larger text or their own colour settings.\n\n## What you need\n\n- Opaque sRGB foreground and background values, or enough compositing evidence to establish the effective colours.\n- Text size in CSS pixels, boldness and whether it qualifies for a stated exception such as inactive controls.\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- What are the exact text and background colours as rendered, including any opacity, overlay or image behind the text? Design-file colours and rendered colours can differ.\n- What size and weight is the text, in CSS pixels or points? The threshold depends on both.\n- Which states should be checked: default, hover, focus, visited, error or disabled? Each colour pair is a separate check.\n- Is the target WCAG 2.2 AA, or a stricter level or local standard?\n\n## Method\n\n1. Establish the effective colours behind the letters as rendered. Composite any transparency over the actual background before measuring. On photos, gradients or overlays, find the lowest-contrast area behind any letter: one failing region is a failure, and one passing sample cannot clear an unknown background.\n2. Convert each 8-bit channel to 0-1 by dividing by 255. Linearise with c\/12.92 when c is at most 0.04045, otherwise ((c+0.055)\/1.055)^2.4. Relative luminance L = 0.2126R + 0.7152G + 0.0722B. Older copies of the formula show 0.03928; W3C says the change makes no practical difference.\n3. Compute the contrast ratio (L1 + 0.05)\/(L2 + 0.05), where L1 is the lighter colour. Ratios run from 1 to 21.\n4. Choose the WCAG 2.2 success criterion 1.4.3 (AA) threshold: 4.5:1 for ordinary text and 3:1 for large-scale text, which is at least 18 point (24 CSS pixels) or 14 point bold (1pt = 1.333px, so about 18.66 CSS pixels). Use the size as delivered, before any zoom by the user.\n5. Compare the unrounded ratio with the threshold: 4.499 does not meet 4.5. Round to two decimals only for display.\n6. Apply the exceptions only where they genuinely fit: text in an inactive control, pure decoration, text nobody can see, text that is part of a picture with plenty of other visual content, and text in a logo have no requirement. Mark these exempt rather than calculating a pass.\n7. Report each state and colour pair separately. For a failure, suggest a darker or lighter replacement colour and give its recalculated ratio.\n\n## Checks before you deliver\n\n- Using a perceived brightness average or comparing rounded ratios gives incorrect decisions near the threshold.\n- The reduced large-text threshold depends on both size and weight. Inactive controls are a separate exception.\n- Measuring a semi-transparent text colour as if it were opaque overstates the contrast. Blend it with the real background first.\n- A text outline counts differently by width. W3C treats a narrow border as part of the letter and a wide halo that fills in the letters as the background.\n- Checking only the default state misses hover, focus, visited and error colours, which are often lighter.\n\n## How to present the result\n\nStart with the result for each item: pass or fail, the ratio to two decimals and the threshold used. Then give a table with each item's colours, size and weight, state, ratio, threshold and result. For each failure, suggest a replacement colour with its recalculated ratio, and list any backgrounds that still need sampling.\n\n## Worked example\n\n**Request:** Check AA contrast for ordinary active text on solid white.\n\n**Supplied material:**\n\n```text\nT1 foreground #777777, background #FFFFFF, 16px regular\nT2 foreground #777777, background #FFFFFF, 24px regular\n```\n\n**Answer:** The 16px text fails AA at 4.48:1 against white. Darken the text and retest for at least 4.5:1 before rounding. The same colour pair passes for the 24px heading, which needs 3:1.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn checks in supplied order as {id,ratio,threshold,result}. ratio is numeric rounded to two decimals and threshold is 3 or 4.5. result is pass or fail. For exempt inactive text or undetermined backgrounds return null for ratio and threshold and result exempt or unknown respectively.\n\n## Sources\n\n- [W3C Understanding Contrast (Minimum)](https:\/\/www.w3.org\/WAI\/WCAG22\/Understanding\/contrast-minimum.html): Explains WCAG 2.2 success criterion 1.4.3 (Level AA): 4.5:1 for text, 3:1 for large-scale text, and the exceptions for inactive components, decoration, invisible text, pictures and logotypes. It says computed values must not be rounded (4.499:1 does not meet 4.5:1) and gives 1pt = 1.333px.\n- [WCAG 2.2 definition of relative luminance](https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-relative-luminance): The normative sRGB formula: the 0.04045 linearisation threshold, the 0.2126, 0.7152 and 0.0722 coefficients, and the note that the earlier 0.03928 value has no practical effect. The same glossary defines the contrast ratio and large-scale text as at least 18 point or 14 point bold.\n- [W3C technique G18 for text contrast](https:\/\/www.w3.org\/WAI\/WCAG22\/Techniques\/general\/G18): G18 measures each letter against the background immediately behind it and describes a halo as a way to keep contrast over varied backgrounds. The skill uses it for text over photos and gradients.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/measure-text-contrast\n","scope":"contextual","trigger_keywords":["Measure text contrast against its background","measure-text-contrast","measure text contrast","Does grey #767676 text on a white background pass WCAG AA?","Does grey #767676 text on a white background pass WCAG AA","colour contrast","color contrast","contrast ratio"],"is_private":true,"is_active":true,"scripts":[{"name":"measure-text-contrast-check","description":"Compare a saved JSON answer with a published test. Pass tests\/case-1\/expected.json (or another case) and the path to your answer.","language":"python","filename":"measure-text-contrast-check.py","content":"from pathlib import Path\nimport runpy\n\nrunpy.run_path(str(Path(__file__).parent \/ 'tests' \/ 'check.py'), run_name='__main__')\n","supporting_files":[{"path":"SKILL.md","content":"---\nname: measure-text-contrast\ndescription: \"Calculate the contrast ratio between text and its background with the WCAG formula and decide pass or fail against the 4.5:1 or 3:1 threshold for its size and weight. Use when someone asks whether text colours, a button label or text over an image meets WCAG AA colour contrast.\"\nlicense: CC-BY-4.0\nmetadata:\n  author: Raq.com\n  version: \"2026-11-22\"\n  homepage: https:\/\/skills.raq.com\/skills\/measure-text-contrast\n---\n\n# Measure text contrast against its background\n\nCalculate text contrast with the WCAG relative luminance formula and apply the size-specific threshold before rounding the result.\n\n## When to use this skill\n\n- Someone gives hex or RGB colours for text and background and asks whether they pass WCAG AA.\n- A design review needs to know whether grey body text, link colours, placeholder text or button labels are readable enough.\n- Text sits over a photo, gradient or semi-transparent overlay and the team wants to know whether it passes.\n\n## When not to use it\n\n- Contrast of icons, focus indicators, chart lines or input borders. Those fall under WCAG 1.4.11 Non-text Contrast (3:1 against adjacent colours), a different check.\n- Enhanced contrast at AAA (WCAG 1.4.6: 7:1, or 4.5:1 for large text) unless the person asks for that level.\n- Judging whether a particular person with low vision can read the text. The ratio is a minimum; some people also need larger text or their own colour settings.\n\n## What you need\n\n- Opaque sRGB foreground and background values, or enough compositing evidence to establish the effective colours.\n- Text size in CSS pixels, boldness and whether it qualifies for a stated exception such as inactive controls.\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- What are the exact text and background colours as rendered, including any opacity, overlay or image behind the text? Design-file colours and rendered colours can differ.\n- What size and weight is the text, in CSS pixels or points? The threshold depends on both.\n- Which states should be checked: default, hover, focus, visited, error or disabled? Each colour pair is a separate check.\n- Is the target WCAG 2.2 AA, or a stricter level or local standard?\n\n## Method\n\n1. Establish the effective colours behind the letters as rendered. Composite any transparency over the actual background before measuring. On photos, gradients or overlays, find the lowest-contrast area behind any letter: one failing region is a failure, and one passing sample cannot clear an unknown background.\n2. Convert each 8-bit channel to 0-1 by dividing by 255. Linearise with c\/12.92 when c is at most 0.04045, otherwise ((c+0.055)\/1.055)^2.4. Relative luminance L = 0.2126R + 0.7152G + 0.0722B. Older copies of the formula show 0.03928; W3C says the change makes no practical difference.\n3. Compute the contrast ratio (L1 + 0.05)\/(L2 + 0.05), where L1 is the lighter colour. Ratios run from 1 to 21.\n4. Choose the WCAG 2.2 success criterion 1.4.3 (AA) threshold: 4.5:1 for ordinary text and 3:1 for large-scale text, which is at least 18 point (24 CSS pixels) or 14 point bold (1pt = 1.333px, so about 18.66 CSS pixels). Use the size as delivered, before any zoom by the user.\n5. Compare the unrounded ratio with the threshold: 4.499 does not meet 4.5. Round to two decimals only for display.\n6. Apply the exceptions only where they genuinely fit: text in an inactive control, pure decoration, text nobody can see, text that is part of a picture with plenty of other visual content, and text in a logo have no requirement. Mark these exempt rather than calculating a pass.\n7. Report each state and colour pair separately. For a failure, suggest a darker or lighter replacement colour and give its recalculated ratio.\n\n## Checks before you deliver\n\n- Using a perceived brightness average or comparing rounded ratios gives incorrect decisions near the threshold.\n- The reduced large-text threshold depends on both size and weight. Inactive controls are a separate exception.\n- Measuring a semi-transparent text colour as if it were opaque overstates the contrast. Blend it with the real background first.\n- A text outline counts differently by width. W3C treats a narrow border as part of the letter and a wide halo that fills in the letters as the background.\n- Checking only the default state misses hover, focus, visited and error colours, which are often lighter.\n\n## How to present the result\n\nStart with the result for each item: pass or fail, the ratio to two decimals and the threshold used. Then give a table with each item's colours, size and weight, state, ratio, threshold and result. For each failure, suggest a replacement colour with its recalculated ratio, and list any backgrounds that still need sampling.\n\n## Worked example\n\n**Request:** Check AA contrast for ordinary active text on solid white.\n\n**Supplied material:**\n\n```text\nT1 foreground #777777, background #FFFFFF, 16px regular\nT2 foreground #777777, background #FFFFFF, 24px regular\n```\n\n**Answer:** The 16px text fails AA at 4.48:1 against white. Darken the text and retest for at least 4.5:1 before rounding. The same colour pair passes for the 24px heading, which needs 3:1.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn checks in supplied order as {id,ratio,threshold,result}. ratio is numeric rounded to two decimals and threshold is 3 or 4.5. result is pass or fail. For exempt inactive text or undetermined backgrounds return null for ratio and threshold and result exempt or unknown respectively.\n\n## Sources\n\n- [W3C Understanding Contrast (Minimum)](https:\/\/www.w3.org\/WAI\/WCAG22\/Understanding\/contrast-minimum.html): Explains WCAG 2.2 success criterion 1.4.3 (Level AA): 4.5:1 for text, 3:1 for large-scale text, and the exceptions for inactive components, decoration, invisible text, pictures and logotypes. It says computed values must not be rounded (4.499:1 does not meet 4.5:1) and gives 1pt = 1.333px.\n- [WCAG 2.2 definition of relative luminance](https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-relative-luminance): The normative sRGB formula: the 0.04045 linearisation threshold, the 0.2126, 0.7152 and 0.0722 coefficients, and the note that the earlier 0.03928 value has no practical effect. The same glossary defines the contrast ratio and large-scale text as at least 18 point or 14 point bold.\n- [W3C technique G18 for text contrast](https:\/\/www.w3.org\/WAI\/WCAG22\/Techniques\/general\/G18): G18 measures each letter against the background immediately behind it and describes a halo as a way to keep contrast over varied backgrounds. The skill uses it for text over photos and gradients.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/measure-text-contrast\n"},{"path":"LICENSE.txt","content":"Original Raq.com instructions and synthetic examples: CC BY 4.0.\nhttps:\/\/creativecommons.org\/licenses\/by\/4.0\/\nAttribution: Raq.com, https:\/\/skills.raq.com\/skills\/measure-text-contrast\nReferenced third-party materials retain their own terms.\n"},{"path":"examples\/worked-example.md","content":"# One pair at two sizes\n\nCheck AA contrast for ordinary active text on solid white.\n\n## Supplied material\n\nT1 foreground #777777, background #FFFFFF, 16px regular\nT2 foreground #777777, background #FFFFFF, 24px regular\n\n## Worked answer\n\nThe 16px text fails AA at 4.48:1 against white. Darken the text and retest for at least 4.5:1 before rounding. The same colour pair passes for the 24px heading, which needs 3:1.\n\n## Reasoning\n\nThe same colours cross the large-text threshold only.\n"},{"path":"tests\/check.py","content":"\"\"\"Check a saved agent answer locally with Python 3 (standard library only).\"\"\"\nimport json\nimport math\nimport sys\nfrom pathlib import Path\n\n\ndef compare(expected, actual, path=\"$\", accepted=None):\n    if isinstance(expected, bool) or isinstance(actual, bool):\n        if expected is not actual:\n            yield path\n    elif isinstance(expected, (int, float)) and isinstance(actual, (int, float)):\n        if not math.isclose(expected, actual, rel_tol=0, abs_tol=1e-8):\n            yield path\n    elif isinstance(expected, dict) and isinstance(actual, dict):\n        for key in sorted(set(expected) | set(actual)):\n            if key not in expected or key not in actual:\n                yield f\"{path}.{key}\"\n            elif not any(\n                not list(compare(option, actual[key]))\n                for option in (accepted or {}).get(key, [])\n            ):\n                yield from compare(expected[key], actual[key], f\"{path}.{key}\")\n    elif isinstance(expected, list) and isinstance(actual, list):\n        if len(expected) != len(actual):\n            yield f\"{path} (length)\"\n        for i, (left, right) in enumerate(zip(expected, actual)):\n            yield from compare(left, right, f\"{path}[{i}]\")\n    elif type(expected) != type(actual) or expected != actual:\n        yield path\n\n\ndef main():\n    if len(sys.argv) != 3:\n        raise SystemExit(\"Usage: python3 check.py expected.json answer.json\")\n    try:\n        expected, actual = [json.loads(Path(p).read_text(encoding=\"utf-8\")) for p in sys.argv[1:]]\n        alternatives = Path(sys.argv[1]).with_name(\"accepted.json\")\n        accepted = json.loads(alternatives.read_text(encoding=\"utf-8\")) if alternatives.is_file() else {}\n    except (ValueError, OSError) as error:\n        raise SystemExit(str(error))\n    differences = list(compare(expected, actual, accepted=accepted))\n    if differences:\n        raise SystemExit(\"Different fields: \" + \", \".join(differences))\n    print(\"Pass\")\n\n\nif __name__ == \"__main__\":\n    main()\n"},{"path":"tests\/README.md","content":"Give your agent SKILL.md and one request.txt in a fresh session. Keep the expected answer aside. Save the reply as answer.json, then run this from the tests folder:\n\n    python3 check.py case-1\/expected.json answer.json\n\nEach case also has an explanation. Where accepted.json exists, the checker accepts the alternatives listed there.\n"},{"path":"tests\/case-1\/request.txt","content":"Check AA contrast for ordinary active text on solid white.\nReturn only the JSON specified in SKILL.md for this test.\n\nT1 foreground #777777, background #FFFFFF, 16px regular\nT2 foreground #777777, background #FFFFFF, 24px regular\n"},{"path":"tests\/case-1\/expected.json","content":"{\n    \"checks\": [\n        {\n            \"id\": \"T1\",\n            \"ratio\": 4.48,\n            \"threshold\": 4.5,\n            \"result\": \"fail\"\n        },\n        {\n            \"id\": \"T2\",\n            \"ratio\": 4.48,\n            \"threshold\": 3,\n            \"result\": \"pass\"\n        }\n    ]\n}\n"},{"path":"tests\/case-1\/explanation.txt","content":"The same colours cross the large-text threshold only.\n"},{"path":"tests\/case-2\/request.txt","content":"Check these controls for the supplied states.\nReturn only the JSON specified in SKILL.md for this test.\n\nA active 16px regular, foreground #000000 on #FFFFFF\nB active 16px regular, white words over a photograph with no sampled background colours\nC inactive disabled control, text #AAAAAA on #FFFFFF\n"},{"path":"tests\/case-2\/expected.json","content":"{\n    \"checks\": [\n        {\n            \"id\": \"A\",\n            \"ratio\": 21,\n            \"threshold\": 4.5,\n            \"result\": \"pass\"\n        },\n        {\n            \"id\": \"B\",\n            \"ratio\": null,\n            \"threshold\": null,\n            \"result\": \"unknown\"\n        },\n        {\n            \"id\": \"C\",\n            \"ratio\": null,\n            \"threshold\": null,\n            \"result\": \"exempt\"\n        }\n    ]\n}\n"},{"path":"tests\/case-2\/explanation.txt","content":"The extremes yield 21:1. A photo cannot be assigned a single reliable result from this description.\n"},{"path":"tests\/case-3\/request.txt","content":"Check large 24px regular white text. The two listed effective colours are the only backgrounds immediately behind any letter.\nReturn only the JSON specified in SKILL.md for this test.\n\nTitle: foreground #FFFFFF; background #000000 behind the first word and #BBBBBB behind the second word.\n"},{"path":"tests\/case-3\/expected.json","content":"{\n    \"checks\": [\n        {\n            \"id\": \"Title\",\n            \"ratio\": 1.92,\n            \"threshold\": 3,\n            \"result\": \"fail\"\n        }\n    ]\n}\n"},{"path":"tests\/case-3\/explanation.txt","content":"White on black passes, but the light patch reduces the ratio to about 1.92:1 behind the second word.\n"}],"is_active":true,"is_approved":false}]}]}