๐ ๐๐จ๐จ๐ค๐ข๐ง๐ ๐ญ๐จ ๐๐๐ ๐ฌ๐จ๐ฆ๐ ๐ข๐ง๐ญ๐๐ฅ๐ฅ๐ข๐ ๐๐ง๐๐ ๐ญ๐จ ๐ฒ๐จ๐ฎ๐ซ ๐๐ซ๐จ๐ง๐ญ๐๐ง๐ ๐๐ฉ๐ฉ? ๐จ๐ค
If you've ever struggled to choose the right text color for a dynamic background (we've all been there ๐โโ๏ธ), hereโs a cool solution using Brain.jsโa simple yet powerful JavaScript library for machine learning right in your browser!
I recently explored Brain.js to solve this very problem: automatically selecting black or white text based on any background color for better readability.
๐ก ๐๐จ๐ฐ ๐๐จ๐๐ฌ ๐ข๐ญ ๐ฐ๐จ๐ซ๐ค?
Train a neural network with sample background colors and the most suitable text color.
Input new background colors and let Brain.js predict which text color (black or white) offers the best contrast.
Implement this directly into your app to make text always readable, no matter the background!
Hereโs an example prediction: For an orange-ish background color { r: 1, g: 0.4, b: 0 }, Brain.js tells me:
White Text: 99% confidence โ
Black Text: 0.2% confidence โ
Top comments (0)