Nice breakdown of choosing text colour using luminance and contrast ratios. Could this approach handle gradient or image backgrounds just as well?
How to Choose the Font Color Based on the Background
2 Comments
Louis Liu
•
@[James Dayal] Whether as a background color or font color, you can calculate the contrast ratio between your chosen font color and background color. The higher the contrast ratio, the more visible your text will be against the background. You can calculate the L of any color by referring to the javascript function I gave in this post.
contrast ratio = (L1 + 0.05) / (L2 + 0.05)
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- Premium Subscription
- Terms of Service
- Refund
- Early Builders
chevron_left
More From Louis Liu
Related Jobs
- Azure DevOps Engineer (Based in California)Pride Global · Full time · United States
- Security Program Manager (EU/UK based)Oneleet · Full time · Italian Republic
- Slalom Flex (Project Based)- Sr. .NET Web App DeveloperSlalom · Full time · Seattle, WA
Commenters (This Week)
Nigel Douglas
1 comment
yashvardhang
1 comment
Wiki khan
1 comment
Contribute meaningful comments to climb the leaderboard and earn badges!