Template:Greater color contrast ratio/doc

From Our World of Text Wiki
Revision as of 13:45, 29 January 2026 by Dat Hack3r (talk | contribs) (Create template documentation)
(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 the higher contrast relative to a given color. This is useful for selecting a foreground/background color pair. By default, the two color options 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 3 or larger for large text, and 4.5 or larger for normal sized text. Colors can be given 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.

  • <span style="{{Greater color contrast ratio|royalblue|css=yes}}">Text with a royalblue background</span>
    Text with a royalblue background
  • <span style="{{Greater color contrast ratio|royalblue|cyan|yellow|css=yes}}">Text with a royalblue background</span>
    Text with a royalblue background

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

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