Bug 488243 - CSS tooling: Add a warning for WCAG 2.0 AA color contrast failures
Summary: CSS tooling: Add a warning for WCAG 2.0 AA color contrast failures
Status: REOPENED
Alias: None
Product: Orion (Archived)
Classification: ECD
Component: JS Tools (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords: accessibility, triaged
Depends on:
Blocks:
 
Reported: 2016-02-22 11:46 EST by Carolyn MacLeod CLA
Modified: 2017-06-06 12:29 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carolyn MacLeod CLA 2016-02-22 11:46:08 EST
Cool feature: If color and background-color are specified together, and if they do not meet a color contrast ratio of 4.5:1, then give a warning that the css rule does not meet the minimum required contrast ratio for WCAG 2.0 AA.

Even cooler, provide a quickfix to suggest what color(s) are needed to pass.

For example, the following rule would fail because gray on aliceblue only has a ratio of 3.68:

.contentassist .proposal-noemphasis-title {
	background-color: aliceblue;
	color: gray;
	padding-top: 5px;
}

The quickfix could change the foreground to #717171:

.contentassist .proposal-noemphasis-title {
	background-color: aliceblue;
	color: #717171;  /* slightly darker than 'gray', to meet WCAG 2.0 AA minimum contrast on aliceblue. */
	padding-top: 5px;
}

If we know the font, then even better, because 18 point or 14 point bold fonts only need to have a ratio of 3:1.

The math (and further info) is here:
https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
(look for definition of contrast ratio, and luminance).

Found this code on StackOverflow:
function luminanace(r, g, b) {
    var a = [r,g,b].map(function(v) {
        v /= 255;
        return (v <= 0.03928) ?
            v / 12.92 :
            Math.pow( ((v+0.055)/1.055), 2.4 );
        });
    return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
}

(luminanace(255, 255, 255) + 0.05) / (luminanace(255, 255, 0) + 0.05); // 1.074 for yellow on white
(luminanace(255, 255, 255) + 0.05) / (luminanace(0, 0, 255) + 0.05); // 8.592 for blue on white
Comment 1 Michael Rennie CLA 2017-01-10 15:44:55 EST
Closing as part of a mass clean up of inactive bugs. Please reopen if this problem still occurs or is relevant to you. For more details see:

https://dev.eclipse.org/mhonarc/lists/orion-dev/msg04002.html
Comment 2 Carolyn MacLeod CLA 2017-06-06 12:29:29 EDT
Reopening, because it would be cool to add this capability to our CSS tooling.

Also, this would count as kudos towards Section 508 Checkpoint 504.2:
"Authoring tools shall provide a mode of operation to create or edit content that conforms to Level A and Level AA Success Criteria and Conformance Requirements in WCAG 2.0".
(We are not technically _required_ to do this because we provide a means of directly editing the source code, however it would be a feature worth blogging about if we did add it).