How to Improve Color Contrast on a Website
A beginner, hands-on guide to improve color contrast on a website with browser inspection, exact code-level changes and verification.
By the end: You will implement and verify improve color contrast on a website on a real local/staging page.
You will implement and verify improve color contrast on a website on a real local/staging page.
Key terms before you start
These definitions make the steps easier to follow and help distinguish controls, files and concepts that can look similar at first.
What you need before starting
- A page you are allowed to edit
- Access to the HTML/CSS/JS or CMS/template that renders it
- A modern browser with Developer Tools
Step-by-step tutorial
Every step is shown below. Work through them in order and use each checkpoint to confirm the result before moving on.
Work on a local or staging copy
Open the project containing the website source. If this is a production site, use a staging copy or backup before structural changes.
A browser page is rendered from source files/CMS output; DevTools edits do not save back to the server.
Move it into the actual source and reload.
Open the page in a modern browser
Load the page, then press F12 or Ctrl+Shift+I (Windows/Linux) to open Developer Tools.
DevTools lets you inspect the DOM, applied CSS, computed sizes, requests and console errors.
Move it into the actual source and reload.
Inspect the text element
Right-click the low-contrast text → Inspect.
You need the computed foreground and actual background.
Move it into the actual source and reload.
Read the computed color
In Computed/Styles note the final color value and source variable/rule.
A token may be better to fix than one local occurrence.
Use the Styles/Computed panels to trace the final value instead of adding stronger selectors blindly.
Inspect backgrounds/layers
Check parent backgrounds, opacity and gradients.
The apparent background may not equal body background.
Use browser contrast tooling
Open the color picker/Accessibility pane where the browser exposes contrast information.
For WCAG Level AA text contrast, normal text needs at least 4.5:1 against its background; large text needs at least 3:1. Browser tooling can calculate the ratio, but you still need to inspect every state and background.
Fix the semantic color token
Change --muted/--text or the component role value when the same problem occurs widely.
Avoid 15 one-off !important patches.
Use the Styles/Computed panels to trace the final value instead of adding stronger selectors blindly.
Check hover/focus/disabled states
Inspect every interactive state.
Default contrast can pass while hover text fails.
Test over images
If text overlays photos, test multiple real images or add a controlled overlay/surface.
A contrast ratio measured on one background patch may not represent the full image.
Test the public/staging URL logged out
Open the final URL in a private/incognito window.
CMS/admin sessions can hide caching, permission or styling differences.
Check caching, loaded asset URL, theme/template and logged-out view.
Document the changed file/rule
Record the file/template/component and purpose of the change in the project notes or version-control commit.
Future maintainers should not have to reverse-engineer why a rule exists.
Check caching, loaded asset URL, theme/template and logged-out view.
Reload the real page and reproduce the result after all temporary DevTools edits are gone.
Concrete examples
Copyable example
:root {
--text:#17191f;
--muted:#5f6670;
--surface:#fff;
}
body { color:var(--text); background:var(--surface); }Troubleshooting
Move it into the actual source and reload.
Check caching, loaded asset URL, theme/template and logged-out view.
Use the Styles/Computed panels to trace the final value instead of adding stronger selectors blindly.
The change has a traceable reason/location.
Continue with these tutorials
Documentation and references
Use these primary and supporting sources to verify current controls, browser behavior and product-specific details.