Color Alone is Not Enough
Color is often used to convey information but keep in mind that user's might not be able to differentiate between colors in a meaningful way.
Use of Color
Color is not used as the only visual means of conveying information, indicating an action, prompting a response, or distinguishing a visual element.
Example: Comparison Chart
I've made a component that takes two values and returns a chart consisting of two elements that get their background colors by different CSS classes. The higher value get's a green color and the lower value get's a red color.
export const ComparisonChart: = ({ firstValue, secondValue }) => {const firstChartStyle =firstValue > secondValue? "green": firstValue === secondValue? "yellow": "red"const secondChartStyle =firstValue < secondValue? "green": firstValue === secondValue? "yellow": "red"return (<div><div><div className={firstChartStyle}></div><div>1</div></div><div><div className={secondChartStyle}></div><div>2</div></div></div>)}
With some additional styling, an input of values 100 and 200 looks something like this:
However, if I look at the WCAG criterion above, you can't rely solely on color to convey information. I need to add more visible elements to the chart.
export const ComparisonChart: = ({ firstValue, secondValue }) => {const firstChartStyle =firstValue > secondValue? "green": firstValue === secondValue? "yellow": "red"const secondChartStyle =firstValue < secondValue? "green": firstValue === secondValue? "yellow": "red"return (<div><div><div className={firstChartStyle}style={{ height: `${ (firstValue + secondValue) / (secondValue * 0.02) }px`}}>{firstValue}</div><div>1</div></div><div><div className={secondChartStyle}>style={{ height: `${ (firstValue + secondValue) / (firstValue * 0.02) }px`}}>{secondValue}<div>2</div></div></div>)}
By showing more information in my chart I can make it much more accessible. Since I already have access to the values of each staple, I can put them inside the colored elements. I also made an inline style that calculates the ratio between the two, based on the range of the values I'm expecting.
Now a user is no longer relying on just the color to find out the higher and lower value. Here demonstrated by inputting the values of 200 and 150: