Nice Web Type

Nice Web Type is one place for web typography, following experiments, advancements, and best practices in typesetting web text. Handcrafted by Tim Brown, Type Manager for Adobe Typekit.

RGBa, text-shadow in Safari, Firefox

While crafting my likes Museo and Sans spec last week, I found that Safari 4 and Firefox 3.5 handle RGBa alpha channel inheritance differently. I’m not sure which way is the right way (or whether, as a matter of W3C spec interpretation, there is a single right way), but both approaches seem logical. Here’s what I learned.

If an element (in our case an H2) uses color:rgba(#,#,#,0.5); and has a text-shadow, the alpha channel value of its color (0.5) is inherited by its text-shadow — in Safari. In Firefox this value is not inherited. Allow me to illustrate a few scenarios.

Hexadecimal colors

Example in Safari 4.0 (above) and Firefox 3.5 (below)

#intro h2 {
	color: #07cefa;
	text-shadow: 18px 0px 0 #ad0918;
	}

We start with regular hex colors – no alpha values, no opacity. Just color, plain and simple.

RGBa … inherited?

Example in Safari 4.0 (above) and Firefox 3.5 (below)

#intro h2 {
	color: rgba(7, 206, 250, 0.5);
	text-shadow: 18px 0px 0 #ad0918;
	}

Here we have RGBa color with an alpha value of 0.5, and our text-shadow still has a hex color. Safari applies the color property’s 0.5 alpha value to the text-shadow too; Firefox does not. Incidentally, the way Safari renders in this example is the look I was going for.

RGBa × 2

Example in Safari 4.0 (above) and Firefox 3.5 (below)

#intro h2 {
	color: rgba(7, 206, 250, 0.5);
	text-shadow: 18px 0px 0 rgba(173, 9, 24, 0.5);
	}

Now we have RGBa color with an alpha value of 0.5, and text-shadow color as RGBa with an alpha value of 0.5. Firefox renders as Safari had in the previous example, because it apparently handles the element and the element’s text-shadow independently. Safari, however, has seemingly multiplied both alpha values to produce a value of 0.25 — lighter than we intended.

Opacity

Example in Safari 4.0 (above) and Firefox 3.5 (below)

#intro h2 {
	color: #07cefa;
	text-shadow: 18px 0px 0 #ad0918;
	opacity: 0.5;
	}

Back to straight hex values this time (no alpha value), but with an opacity of 0.5 applied to the element. Colors match now, as both browsers consider opacity to be inheritable. But the effect we had been striving for is lost; both browsers seem to treat element and text-shadow as a single, flattened layer. This is a nice alternative to have in our toolboxes (imagine the nested opacity/RGBa combos!), but it doesn’t help us with my ALL ABOARD effect.

Inconclusive

As I said, both interpretations seem logical. One might expect RGBa values to be inherited by child elements … though is text-shadow really a child of the element to which it is applied? One might also expect RGBa values not to be inherited: text-shadow has its own parameters, color is one of them, and the alpha channel that’s part of RGBa is technically part of the color. After all, the R, G, and B parts of an element’s RGBa value aren’t inherited.

13 comments

  1. David 13 Jul 2009

    I can’t wait for this to be standard in every browser.

  2. Matt Wiebe 13 Jul 2009

    Thanks for writing up this edge case. Here’s a great example of the need for clearly written and adhered-to web standards!

    It seems to me that Firefox has the right of it here, as rgba is purely a color statement, and abstracting out the alpha component to become opacity for the entire element seems wrong. I poked through the CSS3 spec for a while to see if there was any discussion of this issue, but none came up.

  3. Chad Kaufman 13 Jul 2009

    @David “I can’t wait for this to be standard in every browser.”

    Two letters: IE (in other words, this will never be standard in every browser, just standard in the ones that don’t give web developers high blood pressure)

  4. Philippe 14 Jul 2009

    That is a bug in WebKit (Safari). And fwiw, Opera 10b – or rather the latest snapshot build – agrees with Gecko (Firefox).
    The color part of the value for text-shadow overrides the value (color) set for the color property. If no color is specified on text-shadow, then Gecko and Opera use the value for color. WebKit then plain ignores the text-shadow treating it as if the color value was rgba(0, 0, 0, 0)…).

  5. Sean Curtis 14 Jul 2009

    Firefox has the right of it. From the examples you gave it looks like Safari wouldn’t allow you to render a solid dropshadow with transparent text. I don’t know what case there would be for that but still…

  6. Tim Brown 14 Jul 2009

    Matt, thanks for looking through the CSS spec.

    Philippe, Sean – the more I think about it, the more it makes sense that Firefox is doing this right. I guess, because I built the Museo review while previewing with Safari, the effect seemed to make sense the wrong way because it looked the way I wanted it to look.

    I wonder how often web designers think they’re building something correctly only to find out that their previews are flawed in parallel with their markup and style!

  7. Dave Hyatt 15 Jul 2009

    I think this is a bug in WebKit. More specifically it looks like a bug in CoreGraphics that we will need to just work around in WebKit.

  8. Chris Marsh 15 Jan 2010

    Just came across the same bug whilst playing with text-shadow and RGBa – just to mention that Chrome follows Firefox, and doesn’t allow the alpha channel value to be inherited.

  9. DRoss 30 May 2010

    Dates on comments would be nice…

  10. Webstandard-Blog 16 Nov 2010

    Awesome text-shadow tipps. I really like the idea of giving text an opacity! Thx for sharing!

  11. Joyeria Contemporanea 23 Nov 2010

    Build the Museo review while previewing with Safari, the effect seemed to make

  12. 1y0-a18 2 Dec 2010

    Thanks for sharing… I combine new and so nice post I agree with you. Your supplement is so informative.

  13. silver water 20 Dec 2010

    I struggle with opacity. It took me forever to figure out how to deal with the change of font colors in the different search engines. I used to hate dealing with that. You get used to it, for sure.

Twitter: @nicewebtype
Dribbble: timbrown

Combining Typefaces

 

I wrote a small book about combining typefaces. Buy it for less than the cost of a fancy beverage.