D
D
dollar2019-05-11 19:47:40
Design
dollar, 2019-05-11 19:47:40

How can I determine whether the background color in RGB is light or dark?

There is a background color - it can be anything, even #791
. And there are pre-known and defined light and dark text colors.
For example, light - #fff, #ff0, #0f0
Dark - #800, #000
Obviously, light text will not be visible on a light background, and dark text on a dark one.
How to determine if the background is light or dark (true/false) to match the appropriate text color?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Fedorov, 2019-05-11
@dollar

Quick Google:
https://planetcalc.ru/7779/
https://habr.com/ru/post/304210/

S
Shohruh Shaimardonov, 2019-05-11
@joeberetta

Dark colors if all three values ​​are less than 0.5, and in order to be considered light, it is enough that at least 1 of the 3 colors is greater than 0.5 i.e. RGB(255/2+1, 126, 126) is already light, and RGB(126, 126,126) is dark. Based on this, you can make a mini function that determines light or dark

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question