Yelp

(The Help System)

color.contrast

Get the contrast between two colors.

Parameters

bg

A color specified in hexidecimal, rgb(), or rgba().

fg

A color specified in hexidecimal, rgb(), or rgba().

This template calculates the contrast ratio between colors. The contrast ratio is a number between 1 and 21. The algorithm is defined by the WCAG:

http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef

This template calls color.rl to get the relative luminance of bg and fg. It accepts six-digit and three-digit hexidecimal color codes, colors specified with rgb(), and colors specified with rgba(). It does not accept HSL or named HTML colors. Note that it does not take the alpha value into account when calculating the contrast ratio. Semi-transparent colors will have a lower actual contrast ratio than what is reported by this template.

The WCAG recommends a contrast ratio of at least 4.5 for normal text, and a ratio of at least 3.0 for large-scale text.

Calls Templates