Template:Color contrast/doc

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Usage[edit source]

The template computes color contrast between two RGB colors per WCAG 2.0. The value varies between 1 for identical colors to 21 for maximally contrasting colors (black and white).

The template accepts six unnamed parameters r1, g1, b1, r2, g2, b2 (in this order), representing the RGB color coordinates of the first and second colors. If six parameters are provided, then the template returns the contrast value as described above. There is an additional seventh parameter which can set various minimum contrast levels; if contrast is equal or greater than the provided value, the template will instead return "1" and "0" if not.

Alternatively, the template accepts two parameters representing the HEX codes of two colors, and returns same result.

Examples:

{{color contrast|255|255|255|0|0|0}} → 21
{{color contrast|127|127|127|0|0|0}} → 5.2446151482812
{{color contrast|255|255|255|0|0|0|4.5}} → 1
{{color contrast|127|127|127|0|0|0|7}} → 0
{{color contrast|ffffff|000000}} → 21
{{color contrast|7f7f7f|000000}} → 5.2446151482812