contrastColor (Calculate contrast color)
See also: intToHex (Convert integer to hexa decimal format)
The function $contrastColor calculates either 'black' or 'white' as a contrast of the given color. If the color code is returned as a hexadecimal number, a '#' character will be prefixed automatically, so it can be used in HTML markups.
The function $contrastColor calculates either 'black' or 'white' as a contrast of the given color. If the color code is returned as a hexadecimal number, a '#' character will be prefixed automatically, so it can be used in HTML markups.
Syntax
$contrastColor(color[,resultAsInteger])
Parameter
Name |
Description |
color |
An arbitrary color as positive 16 bit integer or as hexadecimal number with a maximum of 6 digits and preceded by the '#' character. e.g. 9965381 or '9965381' or '#980f45' |
resultAsInteger |
A Boolean value indicating whether the result of the function should be returned as a 16 bit integer (true), Hint: 0 is interpreted as false and 1 is interpreted as true. |
Return value
Black or white as contrast color to the given color.
Examples
Input |
Output |
Color |
color = '#ffffff' |
'#000000' |
Black |
color = '#ffffff' |
0 |
Black |
color = 0 |
'#ffffff' |
White |
color = 0 |
16581374 |
White |
color = '#980f45' |
'#ffffff' |
White |