{"id":119,"date":"2026-11-17T16:40:00","date_gmt":"2026-11-17T16:40:00","guid":{"rendered":"https:\/\/www.masters-tool.com\/blog\/?p=119"},"modified":"2026-11-11T03:39:06","modified_gmt":"2026-11-11T03:39:06","slug":"hex-color-contrast-check-for-ui","status":"publish","type":"post","link":"https:\/\/www.masters-tool.com\/blog\/hex-color-contrast-check-for-ui\/","title":{"rendered":"Checking Hex Color Contrast for UI Text"},"content":{"rendered":"<p><strong>TL;DR \/ Summary:<\/strong> A hex colour that looks fine on your calibrated monitor can fail contrast on a cheap laptop. Convert pairs of hex values into relative luminance, check the contrast ratio against WCAG targets, and fix text or background\u2014not both at random\u2014before shipping UI.<\/p>\n<h2>Contrast is a ratio, not a vibe<\/h2>\n<p>Designers often judge contrast by squinting at a mockup. That habit misses low-vision users, bright outdoor screens, and projectors. The measurable standard is the contrast ratio between text (or UI control) colour and its background.<\/p>\n<p>WCAG expresses success as a minimum ratio: roughly 4.5:1 for normal text and 3:1 for large text under AA. AAA raises the bar further. Your brand palette does not override those floors.<\/p>\n<p>Hex codes alone do not tell you the ratio. You need both colours, converted to luminance, then combined into one number.<\/p>\n<h2>From hex to relative luminance<\/h2>\n<p>Split each hex into red, green, and blue channels from 0 to 255. Convert each channel to a 0\u20131 sRGB value, apply the piecewise gamma expansion used by WCAG, then weight the channels (about 0.2126 R + 0.7152 G + 0.0722 B).<\/p>\n<p>You do not need to memorise the formula if your tool does it, but you do need to know that mid greys are not \u201chalfway\u201d in perception. A jump from #777 to #888 is smaller visually than the hex suggests.<\/p>\n<h3>Pairs you must check<\/h3>\n<ul>\n<li>body text on page background<\/li>\n<li>muted helper text on the same background<\/li>\n<li>button label on button fill<\/li>\n<li>link colour on background, including visited styles<\/li>\n<li>placeholder text inside inputs<\/li>\n<\/ul>\n<p>Placeholder and muted text fail more often than headlines because teams intentionally soften them.<\/p>\n<h2>Fix one side of the pair first<\/h2>\n<p>When a pair fails, change either the foreground or the background, then re-measure. Changing both at once makes it hard to learn which direction restored the ratio.<\/p>\n<p>If the brand colour is sacred, darken or lighten the text sitting on it. If the text colour is sacred, adjust the surface behind it. Document which side is flexible for the next designer.<\/p>\n<p>Utility converters on <a href=\"https:\/\/www.masters-tool.com\/\">Masters Tool<\/a> are handy when you need a quick hex normalisation or format check while you iterate on a failing pair\u2014keep the contrast math attached to the same review pass.<\/p>\n<h2>Opacity and overlays break naive checks<\/h2>\n<p>Semi-transparent text over a photo is not a single hex pair. The effective background is a blend. Sample the actual pixels behind the text in the worst region of the photo, or place a solid scrim behind the type.<\/p>\n<p>Overlays on video need the same treatment. A white caption that works on a dark frame fails when the scene brightens. Prefer a consistent plate behind captions.<\/p>\n<blockquote><p>Measure the colour the eye actually sees, not the token in the design file.<\/p><\/blockquote>\n<p>CSS variables that swap themes multiply the work: check light and dark tokens as separate pairs. A green that passes on white can fail on near-black.<\/p>\n<h2>Large text is not a free pass for everything<\/h2>\n<p>The large-text threshold (roughly 18pt regular or 14pt bold, depending on guidance you follow) allows a lower ratio. Teams misuse this by calling every subtitle \u201clarge.\u201d<\/p>\n<p>If users can zoom or if the type reflows smaller on mobile, design for the smaller size. Passing only at desktop large-text rules is a false win.<\/p>\n<p>Icons that convey meaning without text need contrast too. Decorative icons can be softer; actionable icons should meet UI-component contrast expectations.<\/p>\n<h2>Build a palette matrix instead of one-off checks<\/h2>\n<p>List brand colours as rows and surface colours as columns. Fill each cell with the contrast ratio. The matrix shows which combinations are legal for body text, which are only for large headings, and which are never for text.<\/p>\n<h3>How to keep the matrix honest<\/h3>\n<ul>\n<li>update a cell whenever a token changes<\/li>\n<li>reject new components that invent off-matrix pairs<\/li>\n<li>store hex values in one source of truth, not in screenshots<\/li>\n<\/ul>\n<p>A matrix turns accessibility from a late QA surprise into a design constraint everyone can see.<\/p>\n<h2>Automated checks in the browser<\/h2>\n<p>Browser DevTools and axe-style audits catch many failures on rendered pages. They do not replace the matrix for tokens that have not been used yet, and they can miss text drawn on canvas or inside images.<\/p>\n<p>Run audits on real content, including long paragraphs and error messages. Empty states with giant headings often pass while dense forms fail.<\/p>\n<blockquote><p>Tokens first, then rendered pages. Both layers matter.<\/p><\/blockquote>\n<p>When an audit flags a pair, copy the computed colours\u2014not only the CSS variable names\u2014into your notes. Variables can resolve differently per theme.<\/p>\n<h2>Handing contrast decisions to engineering<\/h2>\n<p>Ship the allowed pairs with the design tokens. Engineers should not invent #5A5A5A because it \u201clooked okay\u201d beside a new card.<\/p>\n<p>If product insists on a soft grey for secondary labels, raise the type size or weight until the ratio passes, or accept that the label must darken.<\/p>\n<p>Contrast work is unfinished until the failing hex pairs are replaced in the source tokens and the matrix cells are updated. Visual preference is allowed inside the legal ratios\u2014not instead of them.<\/p>\n<h2>Dark mode is a second matrix<\/h2>\n<p>Light-theme pairs that pass can fail when backgrounds invert. Build a separate contrast matrix for dark tokens instead of assuming the same hex will stay legal on a near-black canvas.<\/p>\n<p>Check disabled states too. Grey-on-grey often looks intentional until someone tries to read an error under fluorescent office light.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR \/ Summary: A hex colour that looks fine on your calibrated monitor can fail contrast on a cheap laptop. Convert pairs of hex values into relative luminance, check the contrast ratio against WCAG targets, and fix text or background\u2014not both at random\u2014before shipping UI. Contrast is a ratio, not a vibe Designers often judge [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":43,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-everyday-workflows","entry","has-media"],"_links":{"self":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":1,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions\/120"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/media\/43"}],"wp:attachment":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}