cr_get_ratio: Get Contrast Ratio of Two Colors

Description Usage Arguments Value Examples

View source: R/contrast.R

Description

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.

Usage

1
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

1
cr_get_ratio("#FFFFFF", "white")

matt-dray/coloratio documentation built on June 2, 2021, 6:42 a.m.