--- title: "contrastColor (Calculate contrast color)" slug: "calc-function-contrast-color" updated: 2026-05-12T12:44:10Z published: 2026-05-12T12:44:10Z canonical: "docs.lobstersoftware.com/calc-function-contrast-color" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # contrastColor (Calculate contrast color) *See also:* [intToHex (Convert integer to hexa decimal format)](/v1/docs/en/calc-function-int-to-hex) 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. > [!NOTE] > 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. > > > [!TIP] > > **Tooltip** > > > > Syntax: *$contrastColor(color[,resultAsInteger=false])* > > > > | 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. | > > > > 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 |