How to find if a given color is Dark or Light.

Asgar Ali 86 Reputation points
2024-01-16T06:18:38.6166667+00:00

Given a RGB or Hex Value of a color How to find out if the Color is Dark or Light.I am working on a theme where I want to find out if the color is Dark or Light and depending on it I want to set the Text Color to white or Black.

Developer technologies .NET Xamarin
Developer technologies C#
{count} votes

Accepted answer
  1. Ken Kam Hung, Lin 91 Reputation points
    2024-01-16T11:48:32.16+00:00

    To determine whether a color is dark or light, you can calculate the perceived brightness of the color using the following formula:
    Brightness=0.2126R+0.7152G+0.0722B
    where R, G, and B are the red, green, and blue values of the color, respectively. If the brightness value is greater than or equal to 128, the color is considered light. If the brightness value is less than 128, the color is considered dark.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.