Skip to content

Background color is not computed correctly when there are multiple layers of non-opaque background colors #2924

@heryandi

Description

@heryandi

Product: axe-core

Expectation: I expect axe-core to use the right background color value (as can be observed by a color-picker) for color contrast calculation.

Actual: axe-core doesn't seem to calculate the right background color. Seems like it's only wrong when there are multiple layers of non-opaque background colors involved.

Motivation: This should be fixed so the correct color contrast value can be computed.

    axe-core version: 4.2.0

Sample test cases:

  • Case 1
<html>
    <body>
        <div style="background-color: red;">
            <!-- 'blue' with 0.3 alpha -->
            <div style="background-color: rgba(0, 0, 255, 0.3);">
                <!-- 'green' with 0.3 alpha -->
                <div style="background-color: rgba(0, 128, 0, 0.3);">
                    <p>Some text</p>
                </div>
            </div>
        </div>
    </body>
</html>

Expected background color (as picked up by a color-picker): #7C2736
Background-color computed by axe-core (bgColor inside the data field): #7D145B

  • Case 2
<html>
    <body>
        <div style="background-color: rgba(255, 255, 255, 1.0);">
            <!-- 'green' with 0.25 alpha -->
            <div style="background-color: rgba(0, 128, 0, 0.25);">
                <!-- 'red' with 0.5 alpha -->
                <div style="background-color: rgba(255, 0, 0, 0.5);">
                    <p>Some text</p>
                </div>
            </div>
        </div>
    </body>
</html>

Expected background color (as picked up by a color-picker): #DF6F5F
Background-color computed by axe-core (bgColor inside the data field): #AF8860

I think (but not sure) this is because the flattenColors function doesn't apply the simple alpha compositing formula.

I am using a Chrome extension for my color-picker, if that matters: https://chrome.google.com/webstore/detail/colorpick-eyedropper/ohcpnigalekghcmgcdcenkpelffpdolg

Metadata

Metadata

Assignees

No one assigned

    Labels

    color contrastColor contrast issuesfixBug fixesprA pr has been created for the issuerulesIssue or false result from an axe-core rule

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions