Template:Color contrast ratio/doc

From Vietnam Veterans for Factual History
Jump to navigation Jump to search

Lua error: Cannot create process: proc_open(/log/lua.error): Failed to open stream: No such file or directory Lua error: Cannot create process: proc_open(/log/lua.error): Failed to open stream: No such file or directory This template returns the color contrast ratio between the two colors provided. It accepts two parameters, which can be a standard RGB hex color code (#RRGGBB) or a standard HTML color or CSS "orange" (= #FFA500). Color names and hex letters are case-insensitive (i.e. they may be upper- or lower-case).

Usage

Examples with light background

Text
Color
Background
color
Sample Code Contrast
ratio
WCAG 2.0
conf.
Template:Color sample #000000 Template:Color sample #FFFFFF   Sample   {{Color contrast ratio|#000000|#FFFFFF}} Expression error: Unexpected < operator. AAA
Template:Color sample #000080 Template:Color sample #DDDDDD   Sample   {{Color contrast ratio|#000080|#DDDDDD}} Expression error: Unexpected < operator. AAA
Template:Color sample #7B0000 Template:Color sample #FF9900   Sample   {{Color contrast ratio|#7B0000|#FF9900}} Expression error: Unexpected < operator. AA
Template:Color sample #004800 Template:Color sample #AAAAAA   Sample   {{Color contrast ratio|#004800|#AAAAAA}} Expression error: Unexpected < operator. AA
Template:Color sample red Template:Color sample white   Sample   {{Color contrast ratio|red|white}} Expression error: Unexpected < operator. No
Template:Color sample #FF0000 Template:Color sample #FF9999   Sample   {{Color contrast ratio|#FF0000|#FF9999}} Expression error: Unexpected < operator. No

Examples with dark background

Text
Color
Background
color
Sample Code Contrast
ratio
WCAG 2.0
conf.
Template:Color sample #BADFEE Template:Color sample black   Sample   {{Color contrast ratio|#BaDFeE|BlAcK}} Expression error: Unexpected < operator. AAA
Template:Color sample red Template:Color sample black   Sample   {{Color contrast ratio|red|black}} Expression error: Unexpected < operator. AA
Template:Color sample #FFFF00 Template:Color sample #00FFFF   Sample   {{Color contrast ratio|#FFFF00|#00FFFF}} Expression error: Unexpected < operator. No

WCAG 2.0

As a guide to selecting foreground and background colors for text, the Web Content Accessibility Guidelines 2.0 (guideline 1.4) classifies contrast ratios for ordinary text as follows:

WCAG 2.0 text contrast ratios
Font size Not Compliant Level AA Level AAA
Normal < 4.5 4.5 to 7.0 > 7.0
Large (18 pt or 14 pt bold) < 3.0 3.0 to 4.5 > 4.5

Normal wiki-text is rendered by common browsers at roughly 9.5 to 10.5 pt (12.5 to 14 px), depending on skin. Text would need to be about 180% or 140% bold to qualify as "Large" for WCAG purposes.

See also