How to create cool color contrast widgets design
Tags: figma, ui, a11y, tooling
Published: 2024-01-31 08:11:32

For my first Google Developer Expert presentation with the topic, **Getting Started with Designing for Web Accessibility**, I created a presentation talking about color contrast, how to test it and trying to make it as easy to understand as possible with the help of visuals.

## Table of Contents

1. [Tools and Widgets](#one)
2. [How to use the Widgets](#two)
3. [Widget Settings](#three)
4. [Final design that I use for my presentations](#four)

---

## 1. Tools and Widgets<a name="one"></a>

For this particular case, I created the design using the [Figma](https://www.figma.com/) design tool.

I used two widget to create the color contrast cards:

- One widget is called [Color Contrast Checker by Nate Mandreza](https://www.figma.com/community/widget/1233975216424975525). It creates the card.
- The other one is called [Contrast Checker by Zach Inglis](https://www.figma.com/community/widget/1123669584321839030) and createts the small chip.

## 2. How to use the Widgets<a name="two"></a>

Select two colors that you want to compare. Create a new frame in which you want to compare the foreground color with the background color to have them handy.

### 2.1. Color Contrast Checker Card Widget
To use the card widget, enter the HEX color code of your two colors in the input field for the foreground and background. The widget then immediately calculates the contrast and displays the contrast ratio at the top right.

The widget is in light mode. The background is a light greyish color. The first component at the beginning, which displays the WCAG AA criterion and the contrast ratio, has the background color that you set in the input field below.

![Color Contrast Checker shows widget Settings and card results. On the top WCAGs AA criterium is shown with the contrast ratio number of the two colors. Beneath if the HEX Code of the foreground color, beneath that the HEX Code of the background color.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro4232vfucjwmou9yycj.png)

### 2.2. Contrast Checker Chip Widget

For the chip widget to work, you must use it within the frame that you created at the beginning. Set the background color of the frame to the color you will use as the background color and add for example a rectangle (for testing purpose) in the color of the foreground color.

![Figma file hierarchy, showing the frame, and inside the widget as well as the rectangle.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnqnus8n1tozxk91s9g3.png)

Activate the widget. It immediately shows you whether the contrast ratio is good or bad. It adds text inside the widget showing pass or failed as well as an icon, green and checked for pass or red and x for failed. Looks pretty cool, right?

## 3. Widget Settings<a name="three"></a>

The widgets have a variety of settings that you can adjust. You can have them appear in different versions so that you can customize them as you wish.

### 3.1. Color Contrast Checker Card Widget

The widget has three different types of settings. When they are activated, the background color of the button changes from black to blue.

#### Show the widget in dark mode

If you click on the icon in the left-hand corner of the widget, the background color changes to the dark version.

![Widget Settings Bar showing color version switch, Labels settings and Layout setting. The color switch is active.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsjlwe7cq56u57w2fmhp.png)

#### Show labels

It is common to use labels for the colors you have set, especially for larger projects. You can add them by activating the **Show labels** button. 

Input fields appear under foreground and background input fields and the user can enter the desired value.

![Widget Settings Bar shows active Show Label button.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pyc3eu32dfqf7wv35xpi.png)

#### Switch layout

In the settings, you can switch between a horizontal and a vertical layout. The three different settings can be activated partially, all together or not at all.

**Version 1** - Horizontal Layout
![Widget Settings Bar shows active Horizontal Layout button.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/escbwu86f679mhkzcn81.png)

**Version 2** - Dark mode, Show Labels, and Horizontal Layout
![Widget Settings Bar show all the buttons activated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wox05uq6b80gd8oc45rn.png)

### 3.2. Contrast Checker Chip Widget

The widget has five different types of settings.

#### Switch size of widget

You can change the format of the widgets with the third selection element by switching between Tiny Width, Small Width and Large Width.

**Version 1** - Small Width
Showing text if the test has passed or failed and its corresponding icons.
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me7mn1u6pgo6yeay905u.png)

**Version 2** - Tiny Width
Tiny width shows the same as small width but appears in a even smaller format.
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/taoz6uwfgz97hbws3e0z.png)

**Version 3** - Large Width
You get the most out of the information when using Large Width. Color Contrast ratio is shown in parentheses after the icon.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqvvvn0ioes3sxji9n5r.png)

#### Switch Text Size
The second select element of the widget let's you change the text size. Color contrast can pass tests when the text size is large enough. You can switch between Normal Text and Large Text.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sihnqj14f3i76j9f98dg.png)

#### Meeting WCAG AA or AAA

The first select element of the widget let's you change the WCAG criteria you want to meet. Meeting WCAG AA is the norm.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6ho93eh7ccstwafzfpg.png)

#### Change HEX Color Code

The forth button lets you change the HEX Color Code you are going to use as foreground color. It changes the color snippet to the one set on the left corner.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8etl3czsg5zi1ytzdbt5.png)

#### Update color changes

To update the new set color, you have to click on the last button of the widget. The new values will be calculated and the output set to pass or fail.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xm6n3eps8nr4vizbe15.png)

## 4. Final design that I use for my presentations<a name="four"></a>

Here is the final product. With this, I can visually show how color is dependent on each other, how it fails or meets the WCAG guidelines and make it easier for my audience to understand.

![Color contrast checker showing one time failing and one time passing the WCAG requirements foreground on background.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xe14nerd8mlwgq2pmi2c.png)

## Additional Resources

Learn more about the different criteria you have to meet to pass color contrast: [WebAIM Color Contrast Checker](https://webaim.org/resources/contrastchecker/)
My a11y website: [Accessibility First](https://accessibilityfirst.at/)