Template:Greater color contrast ratio/doc

From Our World of Text Wiki
Revision as of 13:55, 29 January 2026 by Dat Hack3r (talk | contribs) (Added {{Lua}})
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

{{Greater color contrast ratio}} determines which of two colors has more contrast relative to a given color. This is useful for selecting a foreground/background color pair. By default, the two candidate colors are white and black, and the selected color pair will always have a contrast ratio greater than 4.58. WCAG 2.0 AA guidelines require a contrast ratio of at least 3 for large text and at least 4.5 for normal sized text. Colors can be specified by name (e.g., royalblue) or as hex triplets, with or without the # prefix (e.g., #4169e1, 4169e1).

If |css=y is set, the template will return valid CSS.

|bias=number specifies a tolerance by which the first color may have a lower contrast ratio than the second and still be selected.

TemplateData

This template determines which of two colors has the higher contrast relative to a given color.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Base color1

The reference color against which contrast is measured (typically the background color)

Example
royalblue
Stringrequired
First option2

The first candidate color to compare for contrast against the base color.

Default
#000000
Example
cyan
Stringoptional
Second option3

The second candidate color to compare for contrast against the base color.

Default
#ffffff
Example
yellow
Stringoptional
CSScss

If set to anything, returns valid CSS in the form of "color: …; background-color: …;" instead of a raw color value

Booleanoptional
Biasbias

A numeric tolerance that favors the first option. The first color may have a contrast ratio up to bias less than the second color and still be selected.

Default
0
Example
0.6
Numberoptional