W3C home > Mailing lists > Public > www-style@w3.org > July 2015

[css-color] rgba() and hsla() functions

From: Simen Mangseth <simen@dansas.no>
Date: Mon, 22 Jun 2015 07:17:22 +0000
Message-ID: <DUB404-EAS35499C499CE8C2F529757D0DDA30@phx.gbl>
To: www-style@w3.org, www-style@w3.org
Hi,


It struck me recently that CSS functions often have optional parameters, and you could see that in the new functions device-cmyk() and hwb(), where the alpha channel could be both omitted or specified, without an extra function. Why isn’t it like that when it comes to rgba() and hsla()? I see the two functions as unnecessary - why not deprecate them and add a fourth optional alpha argument at the end? Fallback compatibility would be the same:


div {


color: rgb(0, 0, 255) /* for older browsers that doesn’t support rgba() nor the new rgb() with 4th alpha argument */;

color: rgba(0, 0, 255, .5) /* for current browsers that doesn’t support the new rgb() with 4th alpha argument */;

color: rgb(0, 0, 255, .5) /* for new browsers that support the new rgb() with 4th alpha argument */

}


I think this would be the better solution going forward. Web developers could continue specifying rgba() and hsla() if they wanted continued support for what in the future could be classified as older browsers (as browser makers wouldn’t drop support for the two functions), and in the future, we would have unified functions, instead of two instances of two very similar functions with the only difference being alpha channel or not. If you want to change a color from transparency to opaque, or the other way around, it is a hassle to:


Remove the letter “a” from “rgba” or “hsla”, and remove the fourth argument, which would be invalid with the (current) rgb()or hsl() function when removing transparency.


Having to add the letter “a” in addition to the fourth argument when wanting transparency.


Use rgba() or hsla() all the time to not having to do this, and having to specify “1” as a fourth argument. I don’t know how it is in other browsers as I haven’t checked that specifically, but in IE 11, the rgba() function is invalid with only 3 parameters.



I really want some insights as to why this was done in the first place, rather than just making an optional fourth parameter. You don’t have to explicitly deprecate neither rgba() nor hsla(), but you could make it an “alias” to the new rgb() and hsl() functions, just like how <link rel="shortcut icon"> or word-wrap still is an allowed alias to <link rel="icon"> and overflow-wrap respectively.


Simen Mangseth

Web developer, Dans AS
Received on Friday, 10 July 2015 08:48:25 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:52:18 UTC