- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Fri, 10 Jul 2015 14:38:43 -0700
- To: Simen Mangseth <simen@dansas.no>
- Cc: www-style list <www-style@w3.org>
On Mon, Jun 22, 2015 at 12:17 AM, Simen Mangseth <simen@dansas.no> wrote: > 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 had the same idea when I was writing the Level 4 version of the Color spec. However, the WG ended up voting against it; making minor changes to APIs like this tends to result in a long period of confusion/error, and when the benefit is nothing more than minor aesthetics, it's difficult to justify. (Note, tho, that if you're comfortable with using hex notation instead, the Color 4 spec *does* add 4/8 digit hex colors, so you can stay with that syntax when you want partially-transparent colors, rather than having to convert to decimal and use rgba(). I don't believe browsers have implemented this yet, tho, but it's a *really* trivial feature (I wrote code to add it to WebKit years ago, before it was in a spec) so you should bug browser vendors that you want it added. ^_^) > 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. Those functions are very old (15-20 years!), and at the time the CSSWG didn't have the design knowledge we have today. Today, we would *absolutely* have just created rgb() and hsl() functions with an optional fourth argument. At the time, this was all rather new, and it was thought that explicit functions with different names would be clearer. (But I wasn't around at the time this was done; Chris Lilley, Bert Bos, or Håkon would probably know better.) ~TJ
Received on Friday, 10 July 2015 21:39:30 UTC