contrast-ratio | contrast ratio between any two valid CSS colors
kandi X-RAY | contrast-ratio Summary
kandi X-RAY | contrast-ratio Summary
A tool to calculate the contrast ratio between any two valid CSS colors.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of contrast-ratio
contrast-ratio Key Features
contrast-ratio Examples and Code Snippets
private static void test() {
final ColorContrastRatio algImpl = new ColorContrastRatio();
final Color black = Color.BLACK;
final double blackLuminance = algImpl.getRelativeLuminance(black);
assert blackLuminance == 0
public double getContrastRatio(Color a, Color b) {
final double aColorLuminance = getRelativeLuminance(a);
final double bColorLuminance = getRelativeLuminance(b);
if (aColorLuminance > bColorLuminance) {
return
Community Discussions
Trending Discussions on contrast-ratio
QUESTION
I want to change the Close Button SVG Color based on what color is used in background I'm using some Sass functions * ($_luminance-list, color-contrast, contrast-ratio, luminance) to control the colors.*
Codepen example:
Here is the Current result:
What I want to achieve:
My Full Code include the functions that I using.
...ANSWER
Answered 2020-Dec-05 at 15:44Simply remove the filter
on .btn-close
, this part:
QUESTION
Given a certain color in HSL (let's say hsl(74,64%,59%)), I want to calculate what darker shade (with the same h and s values) gives me enough contrast to satisfy W3C color contrast requirements.
There are formulas to convert HSL to RGB (for example https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB) and to calculate the relative luminance from that RGB (for example https://www.w3.org/TR/WCAG20/#relativeluminancedef). Based on the color contrast formula (https://www.w3.org/TR/WCAG20/#contrast-ratiodef) I can calculate what the relative luminance for my other color should be.
However, then I'm stuck. I find no way to calculate back from a given relative luminance, to an HSL color with given h and s.
Using tools like https://contrast-ratio.com/ I can just decrease the lightness until it satisfies the requirements, but I would like a formula (preferably in JavaScript) to do this calculation for a large selection of colors.
(I am currently using a binary search method to find the closest value, by testing many conversions from HSL to RGB to relative lightness, but that is quite intensive plus I wonder if the conversion to RGB in between introduces inaccuracies.)
...ANSWER
Answered 2020-May-12 at 21:03Hope this is what you need
Using the formulas in this SO answer, and below:
QUESTION
I work on websites where accessibility is an absolute must have, we aim for at least AA standard. Typically we use resources such as https://contrast-ratio.com and https://contrastchecker.com to test a background colour against black or white text.
In this instance let's take white (#fff) text at a size of 18px. Colour one: #546FAF has a ratio of 4.92 Colour two: #B349B1 has a ratio of 4.66
If I made a linear gradient between those two colours as a background, would #fff text at 18px be safe accessibility wise? I've tried colour picking colours near the text that look close, but hoping it's a simple answer of during that gradient it would never go below the 4.5 ratio.
Thanks!
...ANSWER
Answered 2020-Feb-04 at 21:48Yes you will be safe if both of your colours pass contrast ratio tests, but this is assuming white on a darker gradient background (as you have indicated), for dark colours on a gradient background the opposite is true.
Gradients of two equal (or nearly equal) luminance values when combined tend to get a slight lower luminance value in the middle.
Contrast between two colours is based on luminance using the following formula:-
(L1 + 0.05) / (L2 + 0.05)
where L1 is the relative luminance of the lighter of the colours,
and L2 is the relative luminance of the darker of the colours.
So because gradients tend to get darker in the middle on two similar luminance values you can see that the contrast ratio will increase in the middle (L2 decreases as it gets closer to black, L1
will not change). For this reason the whole spectrum of colour will be above the threshold, with the highest contrast tending towards the centre.
However if you use a dark colour as the foreground colour, then when the gradient darkens in the middle the contrast ratio will decrease (L2
will not change, L1
will decrease).
QUESTION
Let's say I'm using the latest bootstrap. I have my primary color sass variable set to black, so that would mean the default button outline color would be
rgba(0, 0, 0, .25)
, which does not pass WCAG 2.0. Should I override bootstrap's default outline styles for more accessible ones, or does the color contrast of outlines not matter?
ANSWER
Answered 2019-Apr-09 at 09:44Color contrast always matters, whether it is the outlines or any other graphical element of the user interface.
For people using their keyboard to navigate through pages elements and focus them, and who only use visual indication (i.e. not screen readers), developers have to provide some visual hint to let them know the element is focused.
If you change a focused element background color to be visually identified, then outline will not really matter. But if you don't address focus
state styles, you should rely on the outline for the focus
state styles. In this case, you need to make sure outline
styles passe the accessibility tests.
QUESTION
I'm planning on my website having material-inspired design without using a framework. How can I use such iconic material components such as the button ripple and elevation without sacrificing AAA color contrast?
ShadowI want to use the .gmd-2
material shadow from this codepen. It uses two shadows, one with the color rgba(0, 0, 0, 0.16), and the other with the color rgba(0, 0, 0, 0.23), both of which fail AA with a white background, according to https://contrast-ratio.com.
I want to use the Waves light ripple, which is the ripple color rgba(255,255,255,0.4), which doesn't pass AAA even in black.
...ANSWER
Answered 2019-Feb-13 at 13:44You should measure color contrast of text but not shadows of blocks.
Ensure all text elements have sufficient color contrast between the text in the foreground and background color behind it.
https://dequeuniversity.com/rules/axe/3.1/color-contrast?application=AxeChrome
Use right accessibility testing tools https://chrome.google.com/webstore/detail/axe/lhdoppojpmngadmnindnejefpokejbdd
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install contrast-ratio
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page