Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm using color.js to get the color contrast for black text on a solid background color. If the contrast is not good enough (4,5:1), I'd use white instead. I'm using these 2 lines:

const sourceColor = new Color(color); // e.g. color(display-p3 0.718 0.925 0.991)
const contrast = sourceColor.contrastAPCA('black'); // e.g.  89.44591845137951

I'm unsure how I should compare the return number should be compared to the minimum of 4,5:1 provided by APCA. What am I missing?

You must be logged in to vote

If you click on the APCA Guidelines: Bronze Level link on the APCA contrast calculator it will give you a summary of the appropriate levels for various use cases.

For a more details you can read APCA Use Cases and Conformance Research.

And I would also recommend trying out the maximum contrast guidelines for dark mode.

And here's some more links about APCA.

Replies: 2 comments · 1 reply

Comment options

The 4.5:1 contrast ratio is specified by WCAG not by APCA.

If you change the second line to the code below you'll get the contrast ratio you're looking for.

const contrast = sourceColor.contrastWCAG21('black'); // 16.315049658050576
You must be logged in to vote
0 replies
Comment options

Thanks @lloydk I got myself confused 🤦 What output of APCA is considered enough contrast? Or isn't there such thing? I can imagine it depends, but I was hoping to have some reference for typical use cases.

You must be logged in to vote
1 reply
@lloydk
Comment options

lloydk Mar 22, 2024
Collaborator

If you click on the APCA Guidelines: Bronze Level link on the APCA contrast calculator it will give you a summary of the appropriate levels for various use cases.

For a more details you can read APCA Use Cases and Conformance Research.

And I would also recommend trying out the maximum contrast guidelines for dark mode.

And here's some more links about APCA.

Answer selected by svgeesus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.