Browse all tools
Photo and videoCategory overviewPrint Size CalculatorDepth of Field CalculatorCrop Factor and Equivalent Focal Length CalculatorND Filter Exposure CalculatorFlicker-Free Shutter Speed CalculatorTimelapse CalculatorVideo File Size and Bitrate CalculatorAspect Ratio Calculator
Image filesCategory overviewImage Resizer and ConverterPNG to JPG ConverterJPG to PNG ConverterWebP to JPG ConverterJPG to WebP ConverterPNG to WebP ConverterHEIC to JPG ConverterEXIF Metadata Remover
Color and screensCategory overviewColor Converter and Contrast CheckerColor Palette Extractor and GeneratorColor Screen GeneratorDead Pixel TestScreen Refresh and Flicker TestBroken Screen Simulator
Everyday toolsCategory overviewUnit ConverterPercentage CalculatorOnline StopwatchExam Timer

More

All guidesAbout

Color Formats and Contrast: HEX, RGB, HSL and WCAG Explained

Designers describe colors in several formats and need to know whether text stays readable on top of them. Here is how it works.

HEX, RGB and HSL

  • RGB gives the amount of red, green and blue light, each from 0 to 255. For example, rgb(11, 124, 136) is a teal.
  • HEX is the same information in base 16. #0B7C88 means red 0B, green 7C and blue 88. A three-digit code such as #FA0 is shorthand for #FFAA00.
  • HSL describes hue (the color wheel angle from 0 to 360), saturation and lightness. It is the easiest format for making a color lighter, darker or less intense.

What contrast ratio means

The contrast ratio compares the brightness of two colors, from 1:1 (identical) to 21:1 (black on white). The Web Content Accessibility Guidelines (WCAG) set minimums so that people with low vision can read text.

  • AA: 4.5:1 for normal text and 3:1 for large text and interface elements.
  • AAA: 7:1 for normal text and 4.5:1 for large text.

Large text is generally 18 point, or 14 point bold, and above.

Examples

TextBackgroundContrast ratioAA normal text (4.5)AA large text (3)AAA normal text (7)
#000000 #FFFFFF21:1PassPassPass
#1C2024 #FBFCFA15.92:1PassPassPass
#767676 #FFFFFF4.54:1PassPassFail
#999999 #FFFFFF2.85:1FailFailFail
#0B7C88 #FFFFFF4.94:1PassPassFail
#FFFFFF #B5195C6.44:1PassPassFail
#FFFFFF #B9770E3.68:1FailPassFail

Practical tips

  • Gray text is the most common failure. Light gray on white often looks elegant and is hard to read.
  • Text over photos needs a darker overlay or a solid panel behind it.
  • Do not rely on color alone to convey meaning. Add icons, labels or patterns.
  • Check dark mode separately. A color that works on white may fail on black.
  • Use our color converter and contrast checker to test your own pairs.

Why contrast matters

Contrast is not only for people with a diagnosed visual impairment. Text that is easy to read on a laptop in an office becomes hard to read on a phone in bright sunlight, on a dim screen, or for someone who is tired or older. Color vision differences are also common: roughly one in twelve men and about one in two hundred women have some form of color vision deficiency. A design that depends on telling certain colors apart can fail for a noticeable share of visitors.

Worked examples with a teal and a yellow

Using the teal #0B7C88 from the example above, and a bright yellow, here is how different text colors perform:

Text colorBackgroundContrast ratioNormal text (4.5:1)Large text (3:1)
White#0B7C884.94:1PassPass
Black#0B7C884.25:1FailPass
White#FFAA001.91:1FailFail
Black#FFAA0011.00:1PassPass

The lesson is that white text is not automatically the safe choice on a colored button. A bright yellow needs dark text, while a dark teal can take white. The tool above computes the exact figure for any pair, so check before you commit to a brand color.

Beyond the ratio

  • Do not rely on color alone. Pair color with an icon, a label or a pattern, for example an error icon next to a red message.
  • Check interface parts. Buttons, form borders, icons and focus outlines need at least 3:1 against their surroundings.
  • Test text over images. A caption on a photograph can pass in one corner and fail in another. Test the worst area, or add a solid or semi-transparent panel behind the text.
  • Mind light gray text. The lightest gray that passes 4.5:1 on white is #767676, at 4.54:1. Placeholder text and captions are often lighter than that.
  • Check dark mode separately. A palette that passes in light mode can fail when the colors are inverted.

A simple testing routine

  1. List the text and background pairs that appear in your design, including hover and disabled states.
  2. Check each pair, and note the ones that fail.
  3. Adjust the lightness of the text or the background, which is easier to do in HSL than in HEX, until the pair passes.
  4. View the page on a phone outdoors, or with the screen brightness lowered, as a reality check.

Try the tool

Color Converter and Contrast CheckerConvert HEX to RGB and HSL and check text contrast against WCAG accessibility guidelines.

About the author. Darkroom Bench is created and maintained by Andrés, a nature photographer from Argentina with two decades in southern Patagonia and more than 50 trips to Antarctica, whose work has received international awards. Read more or follow the photography on Instagram: @yosoytato.

More guides