Skip to main content
CSS is fun and cool and I like it.
Article

Converting Color Spaces in JavaScript

A challenge I faced in building an image “emojifier” was that I needed to change the color spaces of values obtained using getImageData() from RGB to HSL. I used arrays of emojis arranged by brightness and saturation, and they were HSL-based for the best matches of average pixel colors with the emojis.

In this article, we’ll study functions that will be useful for converting both opaque and alpha-enabled color values. Modern browsers currently support the color spaces RGB(A), hex, and … Read article “Converting Color Spaces in JavaScript”

Article

8-Digit Hex Codes?

Weird right? 4-digit hex codes too. They are a way put alpha transparency information into the hex format for colors. You might be seeing it more all the sudden if you use Chrome, because it dropped in 52, and the DevTools seem to be defaulting to showing alpha transparent colors in this format even if you set it originally using something else.

Firefox supports it too, for the record.… Read article “8-Digit Hex Codes?”

Snippet

How To Generate a Random Color in JavaScript

Here’s a quicky (there is a PHP version too):

var randomColor = Math.floor(Math.random()*16777215).toString(16);

See the Pen
Generate New Random Hex Color with JavaScript
by Chris Coyier (@chriscoyier)
on CodePen.

If you’d prefer they are a bit more pleasing or need to generator colors that work together, we have an article about that. … Read article “How To Generate a Random Color in JavaScript”