Calculate the color contrast ratio of two provided colors. Intended as an visual accessibility aid when selecting a text color to place over a single- color background. The output value should be 4.5 or higher to ensure sufficient contrast and readability. This function is currently based on WCAG 2.1. See WCAG for more information about the calculation.

cr_get_ratio(col_1, col_2, quiet = FALSE, view = FALSE)

Arguments

col_1

Six-digit hex value preceded by '#', or a named color from colors

col_2

Six-digit hex value preceded by '#', or a named color from colors

quiet

Whether to print warning when the ratio value is lower than 4.5.

view

Whether to plot a demonstration of col_1 text on a col_2 background, and vice versa, for visual inspection. Uses cr_view_contrast.

Value

A double.

Examples

cr_get_ratio("#FFFFFF", "white")
#> Warning: Aim for a value of 4.5 or higher.
#> [1] 1