← Web basics: HTML, CSS and JavaScript

Accessibility and contrast

Pages that work for people who see, hear and move differently.

Start this lesson

Accessibility means everyone can use your page, including people who are blind, have low vision or color blindness, or use only a keyboard. You have already met many habits: alt text, labels, headings in order, meaningful link text. Three more: set lang on <html> so screen readers pronounce words correctly; use real <button> elements for things people click, because they work with the keyboard automatically; and make sure text contrasts strongly with its background. The guideline for normal text is a contrast ratio of at least 4.5 to 1.

<html lang="en">

.price {
  color: #1a1a1a;            /* near-black */
  background-color: #ffffff; /* white */
}

<button type="button">Show more</button>

Near-black on white has a contrast ratio of about 17 to 1, easy to read. A pale gray like #bbbbbb on white is only about 1.9 to 1 and fails. The button can be reached with Tab and pressed with Enter or Space without any extra code.

Do not use color alone to carry meaning. "Fields in red are required" fails for color-blind visitors; add a word or symbol too.

Try using your page with only the keyboard: Tab moves forward, Shift+Tab back, Enter activates. If you get stuck, so will others.