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/doc







Add links
 









Template
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



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




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< Template:Greater color contrast ratio

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

[edit]

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

[edit]
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

[edit]



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

Hidden category: 
Template documentation pages
 



This page was last edited on 28 August 2021, at 09:02 (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