Last month, we looked at a technique for generating random colors with vanilla JS.
Reader Stephen Flannery showed me a demo he built with the technique where the text color changed from black to white if the color was too dark.
Checking color contrast with vanillia JS When I asked Stephen how he did it, he pointed me to this article from Brian Suda at 24 Ways on checking color contrast.