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.
Tooltip
Syntax: $contrastColor(color[,resultAsInteger=false])
Name
Description
colorAn 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(
optional)A Boolean value indicating whether the result of the function should be returned as a 16 bit integer (true),
or as a 6 digit hexadecimal number preceded by the '#' character (false).
If this parameter is not given at all, it will be interpreted as false.
Hint: 0 is interpreted as false and 1 is interpreted as true.
Returns black or white as a contrast color to the transferred color.
Example: $contrastColor(#980f45) – returns #ffffff (White)
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 (optional) | A Boolean value indicating whether the result of the function should be returned as a 16 bit integer (true), or as a 6 digit hexadecimal number preceded by the '#' character (false). If this parameter is not given at all, it will be interpreted as false. 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' resultAsInteger = false | '#000000' | Black |
color = '#ffffff' resultAsInteger = true | 0 | Black |
color = 0 resultAsInteger = false | '#ffffff' | White |
color = 0 resultAsInteger = true | 16581374 | White |
color = '#980f45' | '#ffffff' | White |