How to Fix a Single Color Pair¶
Fix one text color that’s hard to read on its background.
The problem¶
You have a text color and background color. The text is hard to read.
The solution¶
Use ColorPair and call make_readable():
from cm_colors import ColorPair
pair = ColorPair("#777777", "#ffffff")
readable_color, success = pair.make_readable()
# Use readable_color instead of #777777
print(readable_color) # '#757575'
How it works¶
Create a
ColorPairwith your text and background colorsCall
make_readable()to get a fixed colorUse the fixed color in your design
The function returns two values:
readable_color: The fixed color (same format as your input)
success:
Trueif the color is now readable
Real examples¶
Fix hex colors¶
from cm_colors import ColorPair
pair = ColorPair("#999999", "#ffffff")
fixed, success = pair.make_readable()
# fixed is '#8e8e8e' (darker gray)
Fix RGB tuples¶
from cm_colors import ColorPair
text = (150, 150, 150)
bg = (255, 255, 255)
pair = ColorPair(text, bg)
fixed, success = pair.make_readable()
# fixed is (142, 142, 142) - preserves tuple format
Check if colors already readable¶
from cm_colors import ColorPair
pair = ColorPair("#000000", "#ffffff")
if pair.is_readable == "Very Readable":
print("Colors are good")
else:
fixed, success = pair.make_readable()
print(f"Use {fixed} instead")
Large text (bigger fonts)¶
If your text is large (24px or bigger, or 19px+ bold), tell the function:
from cm_colors import ColorPair
# For headings, large buttons, etc.
pair = ColorPair("#888888", "#ffffff", large_text=True)
fixed, success = pair.make_readable()
Want very readable colors¶
For extra readability:
from cm_colors import ColorPair
pair = ColorPair("#777", "#fff")
fixed, success = pair.make_readable(very_readable=True)
Common issues¶
“Colors changed too much”
Use strict mode to minimize changes:
fixed, success = pair.make_readable(mode=0)
“Have many colors to fix”
Use the bulk function instead: How to Fix Multiple Colors at Once
“Need a report showing changes”
Generate an HTML report:
fixed, success = pair.make_readable(save_report=True)
# Creates cm_colors_quick_report.html
See also¶
How to Fix Multiple Colors at Once - Fix many colors at once
ColorPair API Reference - Full API reference
Troubleshooting Common Issues - More solutions
Fix Unreadable Colors in Python - Back to main page