Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Parameters  





2 Examples  





3 See also  














Template:Greater color contrast ratio






العربية

Авар
Azərbaycanca
تۆرکجه
Basa Bali
Bamanankan

 / Bân-lâm-gú
Беларуская (тарашкевіца)

Български
Bosanski
Буряад
Català
Čeština
Chi-Chewa
ChiShona
Dansk
الدارجة
Eesti
Ελληνικά
Español
Esperanto
فارسی
Føroyskt
Gaeilge

Hausa
Հայերեն
Hrvatski
Igbo
Bahasa Indonesia
IsiZulu
Íslenska
Italiano
Jawa

Ladin
ि
Македонски

Malti
Bahasa Melayu
 / Mìng-dĕ̤ng-nḡ
Монгол
Nederlands


Oʻzbekcha / ўзбекча

Papiamentu
Português
Русский
Scots
Shqip

Simple English
Slovenčina
Slovenščina
Soomaaliga
کوردی
Српски / srpski
Srpskohrvatski / српскохрватски
Sunda
Svenska
Tagalog
ி
Taqbaylit


Türkçe
Basa Ugi
Українська
اردو
Tiếng Vit


 

Edit links
 









Template
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Meta-Wiki
 
















Appearance
   

 





Permanently protected template

From Wikipedia, the free encyclopedia
 


This template determines the pair of colors with the larger contrast ratio: color1/color2 or color1/color3. This is useful for selecting a foreground/background color pair. For accessibility, 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.

In the default mode, color2 and color3 are white and black, and the selected color pair will always have a contrast ratio greater than 4.58.

Parameters

A color input can be by name ("khaki") or hextriplet with/without #-prefix ("#F0E68C", "F0E68C")   

|1= (required): background color
|2= first fontcolor. Optional, default = white (#FFFFFF)
|3= second fontcolor. Optional, default = black (#000000)
The template returns the fontcolor with the greatest contrast
background is   Khaki (#F0E68C): {{Greater color contrast ratio|khaki|white|black}} → black
background is   RoyalBlue (#4169E1): {{Greater color contrast ratio|#4169E1|FFFFFF|000000}} → FFFFFF (=white)
css text
  Khaki (#F0E68C): {{Greater color contrast ratio|khaki|white|black|css=y}}
background-color:khaki; color:black;
Example 1,   Khaki (#F0E68C)
<span style="font-size:110%; {{Greater color contrast ratio|khaki|white|black|css=y}}">Example text on khaki background.</span>
<span style="font-size:110%; background-color:khaki; color:black;">Example text on khaki background.</span>
Example text on khaki background.
Example 2,   #4169E1 (RoyalBlue)
<span style="font-size:110%; {{Greater color contrast ratio|#4169E1|#ffffff|#000000|css=y}}">Example text on #4169E1 background.</span>
<span style="font-size:110%; background-color:#4169E1; color:#ffffff;">Example text on #4169E1 background.</span>
Example text on #4169E1 background.
bias
This parameter should be used with caution to ensure accessibility. As stated above, when used without a bias, and with color2 and color3 equal to white and black, the selected color pair will always have a contrast ratio greater than 4.58.

Examples

Navy
Red
White
Black
#005500
CC5500
CC5500, |bias=1
error
(returns background-color:Not a color; color:;, and so no color is set; defaults to black-on-white.)
(returns background-color:Navy; color:;, and so no fontcolor is set; defaults to black. The template did not function.)

See also


Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:Greater_color_contrast_ratio&oldid=827245316"

Categories: 
Lua-based templates
Color conversion templates
Hidden category: 
Wikipedia template-protected templates
 



This page was last edited on 23 February 2018, at 16:29 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki