Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

AccessibleColors

Guides

  • AccessibleColors

Tech Notes

  • Designing Accessible Color Schemes

Symbols

  • AccessibleTextColor
  • AdjustForContrast
  • WCAGContrastRatio
  • WCAGLevel

Overviews

  • AccessibleColors
Designing Accessible Color Schemes
Color choices that look fine to one reader can be illegible to another. The Web Content Accessibility Guidelines (WCAG) make legibility measurable through a contrast ratio between a foreground and a background color. AccessibleColors brings that measure to the Wolfram Language and builds a few practical tools on top of it. This tech note walks through a typical workflow: measure contrast, read off a conformance level, pick legible text, and repair a color that falls short.
Measuring Contrast
WCAGContrastRatio
returns a number from 1 (the two colors are identical) to 21 (black on white). It depends only on relative luminance, so it is symmetric in its two arguments.
In[1]:=
WCAGContrastRatio
[Black,White]
Out[1]=
21.
A mid gray on white is far weaker:
In[2]:=
WCAGContrastRatio
[Gray,White]
Out[2]=
3.97665
Reading Conformance Levels
Raw ratios are easier to act on as WCAG levels.
WCAGLevel
buckets a pair into
"AAA"
or
"AA"
using the 4.5 and 7 thresholds for normal text, and returns a
Missing["BelowThreshold",...]
(carrying the ratio it fell short by) otherwise:
In[3]:=
AssociationMap
WCAGLevel
[#,White]&,{Black,GrayLevel[0.3],Gray,LightGray}
Out[3]=

AAA,
AAA,
Missing[BelowThreshold,Ratio3.97665,Minimum4.5],
Missing[BelowThreshold,Ratio1.41496,Minimum4.5]
Large text is held to looser thresholds, which the
"LargeText"
option selects:
In[4]:=

WCAGLevel
[Gray,White],
WCAGLevel
[Gray,White,"LargeText"True]
Out[4]=
{Missing[BelowThreshold,Ratio3.97665,Minimum4.5],AA}
Choosing Legible Text
Given a background,
AccessibleTextColor
returns whichever of black or white contrasts with it more strongly, so labels stay readable on any swatch:
In[5]:=
RowTableFramedStyle"Ag",
AccessibleTextColor
[bg],18,Backgroundbg,FrameMargins8,{bg,{LightBlue,Darker[Red],Yellow,RGBColor[0.1,0.1,0.4]}}
Out[5]=
Ag
Ag
Ag
Ag
Repairing a Color
When a chosen color is too weak,
AdjustForContrast
nudges it toward black or white until it just clears the target ratio (AA by default), leaving the hue as intact as it can:
In[6]:=
before=Gray;​​after=
AdjustForContrast
[before,White];​​after,
WCAGContrastRatio
[after,White],
WCAGLevel
[after,White]
Out[6]=

,4.5,AA
Asking for the stricter AAA threshold pushes it further:
In[7]:=
WCAGContrastRatio

AdjustForContrast
[Gray,White,"Target"7],White
Out[7]=
7.
Together these four functions cover the everyday accessibility loop: measure, grade, choose, and repair.
RelatedGuides
▪
AccessibleColors
""

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com