W3C home > Mailing lists > Public > www-style@w3.org > September 2010

Fwd: Propsal: Mechanism for converting rgb, hex, and named color strings between one another

From: Daniel Buchner <daniel@mozilla.com>
Date: Fri, 24 Sep 2010 16:22:26 -0700
Message-ID: <AANLkTimcoDU=d+kmX14VHf4NbSEPtHjLZ2xAuiLH+YWg@mail.gmail.com>
To: www-style@w3.org
Hey W3'ers!

Below is a forwarded copy of a proposal I made to the what-wg that received
positive feedback there along with a request to point the proposal here to
this group. Please let me know what you think, I'd love for all the major JS
libs to be able to remove all the many lines that are associated with
converting HEX to RGB and the inverse, as well as getting value conversions
for named colors.

Thank you for your time!

- Daniel

---------- Forwarded message ----------
From: Daniel Buchner <daniel@mozilla.com>
Date: Wed, Sep 22, 2010 at 2:44 PM
Subject: Propsal: Mechanism for converting rgb, hex, and named color strings
between one another
To: whatwg@whatwg.org
Cc: sicking@mozilla.com

Hello whatwg!

Many developers, js libraries, and frameworks interact with colors in a
variety ways in their pages and apps. One common action they perform in many
of these interactions is to convert colors between RGB and HEX. A fair
amount of js is needed to do this type of thing, see the following examples:
converting hex to rgb in

I propose that we provide a way for developers to get all color equivalents
of a valid color string - red, #ff0, rgb(255, 0, 0).

Currently to derive RGB or HEX values from a named css color there is even
more craziness required. You must create a dummy element, inject it into the
DOM, set styles, get the computed styles, and finally perform various
validity checks to ensure the correct output: Here is an implementation I
put together to convert named colors to RGB or HEX: named colors to hex and
try typing in 'red', 'magenta', etc.

The very fact that the colors can be converted via the implementation I use,
indicates the look-up is already present in browsers, there is just nothing
exposed to developers to take advantage of it.

Received on Saturday, 25 September 2010 09:15:33 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:49:48 UTC