Sunday, May 18, 2014

Calculating colour contrast from hex colour code (php, javascript)

This time I have a nice little snippet to offer you: there is an easy way of calculating contrast from hex colour codes. I needed this on one of my web apps where I wanted to display the background of certain buttons in one colour and wanted the app to automatically calculate if I should set black or white as foreground colour for the button so it's easy to read.

It is explained very nicely in the following article: Calculating Color Contrast.

Hope you'll like it and make good use of it, just like I did. ;)

No comments:

Post a comment

Dear legitimate commenters, please post your comments below. I'd be happy to receive your feedback; helps me a lot improving, or getting reassurance that I'm doing something really great here.

IMPORTANT! A note to commenters planning on advertising their business in comments: please be informed that I'm NOT going to post your comments but will ALWAYS mark them as SPAM.