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
4 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
- Lead Laravel PHP Software Developer (Chicago Based)Highland · Full time · Chicago, IL
- Lead Laravel PHP Software Developer (Chicago Based)Highland · Full time · Chicago, IL
- Lead Laravel PHP Software Developer (Chicago Based)Highland · Full time · Chicago, IL
Commenters (This Week)
cgutierrez1145
4 comments
firatcelik
1 comment
Gavin Cettolo
1 comment
Contribute meaningful comments to climb the leaderboard and earn badges!