Jump to content

Module:Color contrast/doc

From The Perfect Tower II
Revision as of 01:50, 7 October 2026 by Speedybrain (talk | contribs) (Documentation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:Color contrast

Computes the relative luminance of CSS colors and the contrast ratio between two colors (the WCAG formula). It is an older copy of Wikipedia's Module:Color contrast.

On this wiki only Module:Navbox uses it: on template pages, _styleratio checks every *style parameter of a navbox, and a ratio below 4.5 adds the tracking category "Potentially illegible navboxes". The wrapper templates named at the top of the source ({{Color contrast ratio}} and others) don't exist here.

Colors can be CSS names (looked up in Module:Color contrast/colors), #rgb, #rrggbb, rgb() with numbers or percentages, and hsl(). A color it can't read gives an empty string.

Entry points for #invoke take positional arguments from the invoke, or from the calling template when the invoke has none:

  • lum: the luminance of color 1, from 0 (black) to 1 (white).
  • ratio: the contrast ratio of colors 1 and 2. error sets the text for colors it can't read (default ?).
  • styleratio: the contrast between background or background-color and color in the CSS text 1. 2 and 3 are the background and text colors to assume when the CSS doesn't set them (white and black).
  • greatercontrast: of colors 2 (default white) and 3 (default black), the one with more contrast against color 1. bias favors color 2; css returns a background-color: …; color: …; declaration instead.

Lua modules call the same functions with an underscore: _lum(color), _ratio(args), _styleratio(args) and _greatercontrast(args).