Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contrast analyser doesn't factor in CSS shadow #246

Closed
DavidMacDonald opened this issue Oct 30, 2016 · 18 comments
Closed

Contrast analyser doesn't factor in CSS shadow #246

DavidMacDonald opened this issue Oct 30, 2016 · 18 comments
Assignees
Labels
color contrast Color contrast issues fix Bug fixes rules Issue or false result from an axe-core rule wai-tools

Comments

@DavidMacDonald
Copy link

A client who met contrast minimums by creating a 360 degree shadow around text. aXe measured foreground text and background but did not factor in the shadow... this would be tricky programming to remedy. It would require ensuring the shadow surrounds the text and that the shadow is sufficient, but I think it's worth investigating further, because I've had to over ride the aXe report.

@marcysutton
Copy link
Contributor

We should be able to check for a CSS text-shadow if it's directly on the element (and not a pseudo-element). But how much blur, spread, etc. makes the shadow readable? We'd have to compare those values along with shadow color to the text and background colors to see if there is enough of a difference.

@marcysutton marcysutton added rules Issue or false result from an axe-core rule color contrast Color contrast issues and removed rules Issue or false result from an axe-core rule labels Nov 1, 2016
@Volker-E
Copy link

Volker-E commented May 11, 2017

We've been running into this question ourselves without finding a distinct boundary.
Blur < 5px and offsets < 2px seemed to be approximations.

github - axe - 246 - oojs ui demos 2017-05-10

Disabled text input placeholder in [OOjs UI](https://github.com/wikimedia/oojs-ui/) at 400% zoom

@dylanb
Copy link
Contributor

dylanb commented May 11, 2017

@DavidMacDonald how did you determine that the contrast was sufficient using the shadow?

@Volker-E (side note: disabled elements do not have to meet the contrast minimums)

@DavidMacDonald
Copy link
Author

That's where I use the Colour Contrast Analyser eyedroppers :)

@dylanb
Copy link
Contributor

dylanb commented May 17, 2017

@DavidMacDonald What I mean by that question is, what relationship between the font-size/weight and the shadow-size leads to the same ability to read the text at the threshold contrast ratio? Do you have any research that backs up the claim that the shadow contrast is equivalent to the same background color?

@DavidMacDonald
Copy link
Author

DavidMacDonald commented May 17, 2017

In WCAG, there is no distinction between shadow and background. The text needs to have sufficient colour with its adjacent color (or outline) which we call background. When CSS shadow is used, it becomes the background as long as it is 1px. See Note 5 on the definition of contrast ratio

@dylanb
Copy link
Contributor

dylanb commented May 18, 2017

@DavidMacDonald how do you determine whether the shadow definition actually results in a background that is at least 1px wide around the entire letter?

@WilcoFiers
Copy link
Contributor

@DavidMacDonald I don't think it's quite as easy as you're saying it. Check out this codepen:
https://codepen.io/wilcofiers/pen/Kmxrra

In theory, all of these meet the color contrast, if you take the color of the text-shadow in place of the background. But offset and blur radius impact that quite a bit. Can you make a suggestion on how to deal with those?

@DavidMacDonald
Copy link
Author

DavidMacDonald commented May 18, 2017

I agree, it would take some clever programming, and no one has done that before... some investigation of threshold blur etc... it would make you guys rock stars :)

This is not a simple bug fix, and may be a future investigation. But it is possible to test manually with eyedroppers, so perhaps it can be done automatically.

Perhaps a short term solution is to say something like "failure of contrast, shadow is being used which may cause it to pass, manual check necessary..."

@dylanb
Copy link
Contributor

dylanb commented May 18, 2017

@WilcoFiers @marcysutton WDYT - should we turn this into two different tickets:

  1. look for a shadow and place it into review items
  2. longer term, research looking for shadow width and doing this totally automatically

@WilcoFiers
Copy link
Contributor

Nah. I think we can take this on in one go. I just have to figure out how to come up with a percantage of how much of the shadow's color we should mix with the background color. WCAG doesn't give us anything for that, but we can just put together a few examples and give those the numbers we feel are reasonable.

@DavidMacDonald
Copy link
Author

the other trick is to ensure it's a 360 degree shadow, which requires two shadows, because it has a right left offset and a top bottom offset.

@tlobinger
Copy link

+1 on solving the issue

I think it should be easy/easier to calculate the merged colors if the assumption is the shadow is applied without offset. In that case the gradient can be calculated and what should matter is the color of the first pixel merged on top of the background. This new color becomes effectively an outline of the text..

So I would suggest for now to ignore shadow offsets and solving the issue for gradient backgrounds.
So limit the solution to solving this case https://jsfiddle.net/aq9Laaew/51325/

@dylanb
Copy link
Contributor

dylanb commented Jun 26, 2018

@tlobinger I agree this would be a good first case to solve-for

@WilcoFiers comments?

@gulzarsingh591
Copy link

I am facing a similar issue while validating the text color(foreground) with text shadows(background) using axe.
In my case, we need to maintain the brand colors as well as the A11y contrast ratio. So to achieve both, we are referring a G18 technique which w3c is recommended. It says

If the background or the letters vary in relative luminance (or are patterned) then the background around the letters can be chosen or shaded so that the letters maintain a 4.5:1 contrast ratio with the background behind them even if they do not have that contrast ratio with the entire background.

Here is the link - https://www.w3.org/TR/WCAG20-TECHS/G18.html

Not sure if your tool is programmed to pick the text shadows as background. Is the axe tool updated with this enhancement?

@WilcoFiers
Copy link
Contributor

Here's another example of this:

Source: https://act-rules.github.io/rules/afw4f7#passed-example-4

<p style="color: #000; background: #737373; text-shadow: white 0 0 3px">
	Some text in a human language
</p>

@WilcoFiers WilcoFiers added fix Bug fixes rules Issue or false result from an axe-core rule wai-tools labels Mar 24, 2020
@WilcoFiers WilcoFiers self-assigned this Mar 25, 2020
@padmavemulapati
Copy link

padmavemulapati commented Jul 27, 2020

Verified with the latest axe-core(3.5.5) code base ,
testfile - `


Some text in a human language

` also verified on test file ` Hello world <script> window.addEventListener('load', function() { var span = document.getElementById('span') var style = window.getComputedStyle(span) console.log(style.getPropertyValue('text-shadow'))
});

</script> `
image

image

@jeankaplansky
Copy link
Contributor

included in internal release notes 7/27/2020

mrtnvh pushed a commit to mrtnvh/axe-core that referenced this issue Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color contrast Color contrast issues fix Bug fixes rules Issue or false result from an axe-core rule wai-tools
Projects
None yet
Development

No branches or pull requests

9 participants