Skip to article content
FrontendXLesson 13 / 30

Color contrast, target size and visual accessibility

Build semantic, accessible and responsive interfaces from a blank page, and explain why each layout and styling decision works.

intermediate · about 30 minutes · 2 exercises

  • Predict
  • Debug

What you will be able to do

#
  • Check text and UI contrast against WCAG 2.2 AA thresholds.
  • Avoid conveying information by color alone.

Overview

#

WCAG 2.2 AA requires a contrast ratio of at least 4.5 to 1 for normal text and 3 to 1 for large text, which is 18.66px bold or 24px regular. Non-text elements such as input borders, icons that carry meaning, and focus indicators need 3 to 1 against their background. These ratios are measured, not eyeballed.

Color alone must never carry meaning. A form that marks errors only in red, or a chart that distinguishes series only by hue, fails for color-blind users and in high-contrast modes. Add an icon, a label, a pattern or a shape.

snippet.html
<!-- wrong: color is the only signal -->
<p style="color: #d00">Invalid</p>

<!-- right: text and color -->
<p class="error">
  <svg aria-hidden="true"><!-- warning icon --></svg>
  Invalid: enter a date after today.
</p>

Target size is the other half of visual accessibility. WCAG 2.2 adds a minimum target size of 24 by 24 CSS pixels for pointer inputs, with spacing exceptions. Small icon buttons crammed together are hard to hit for anyone with a tremor or a large thumb. Increase the hit area with padding even when the visual icon stays small.

Respect user preferences. prefers-reduced-motion lets you drop large animations, and prefers-contrast and forced-colors mode change how your colors render. Test with the operating system settings, not only the default theme.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Debug

    This status indicator uses color alone. Make it understandable without color.

    starter.html
    <span style="color: green">Passed</span>
    <span style="color: red">Failed</span>

    Reveal the reference answer
    reference.html
    <span class="status status--pass"><svg aria-hidden="true"><!-- check icon --></svg> Passed</span>
    <span class="status status--fail"><svg aria-hidden="true"><!-- cross icon --></svg> Failed</span>

    Authored expected output: Each status has a text label and a distinct icon so the meaning survives without color.

    Text plus a shape carries the meaning; color becomes reinforcement rather than the only signal.

  2. Exercise 2Predict

    What is the minimum contrast ratio WCAG 2.2 AA requires for normal body text?

    Choose the best answer

Common misconceptions

#
  • If a designer picked the colors, contrast is fine.
  • A 3:1 ratio is enough for all text.

Follow-up practice

#
  • html-css-14-aria-roles-states

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.