63

In one of my other questions, the solution to fixing a rendering issue was by using the value rgba(255, 255, 255, 255) instead of transparent. We tested using rgba(0, 0, 0, 0) and this still corrected the problem, meaning that it is the definition of transparent that causes the error. However, looking at the W3C CSS3 Specification (and MDN reference) for transparent reveals that rgba(0, 0, 0, 0) and transparent should be equal:

transparent

Fully transparent. This keyword can be considered a shorthand for transparent black, rgba(0,0,0,0), which is its computed value.

So what gives? Why can two, seemingly, identical values produce different results? I've looked into the formatting of RGBA, and looked for similar questions (to no avail). Every question/answer that mentions the conversion from transparent to rgba(0,0,0,0) always has the words 'should' or 'according' in. (For example here). What is the actual difference, and why does it change the output so much?

N.B: This occurs in most, if not all, versions of Internet Explorer. We also know that it occurs in some versions of Firefox. However Chrome and Safari do not display this behaviour, leading us to believe that there is some sort of patch for this in -webkit.


To be able to submit this as a bug we need to reproduce the problem using the minimal amount of code. So, transferred from my other question, here is a comparison of using transparent vs rgba(0,0,0,0), and what happens when we use both.

Transparent

@keyframes spin{
 0% {transform:rotateZ(0deg);}
 50% {transform:rotateZ(360deg);border-radius:60%;}
 100%{transform:rotateZ(720deg);}
}
.spinme{
 display:inline-block;
 position:relative;
 left:0;
 top:0;
 margin:0.2rem;
 width:0.8rem;
 height:0.8rem;
 border:0.2rem solid black;
 border-radius:0%;
 outline: 1px solid transparent;
 transform:rotateZ(0deg);
 animation: spin infinite 4s;
}
<div class="spinme"></div>

RGBA(0,0,0,0)

@keyframes spin{
 0% {transform:rotateZ(0deg);}
 50% {transform:rotateZ(360deg);border-radius:60%;}
 100%{transform:rotateZ(720deg);}
}
.spinme{
 display:inline-block;
 position:relative;
 left:0;
 top:0;
 margin:0.2rem;
 width:0.8rem;
 height:0.8rem;
 border:0.2rem solid black;
 border-radius:0%;
 outline: 1px solid rgba(0,0,0,0);
 transform:rotateZ(0deg);
 animation: spin infinite 4s;
}
<div class="spinme"></div>

Both

As pointed out by @andyb, there is strange behaviour when using both on separate elements. You would expect only one to wobble, however they both do. As demonstrated:

@keyframes spin{
  0% {transform:rotateZ(0deg);}
  50% {transform:rotateZ(360deg);border-radius:60%;}
  100%{transform:rotateZ(720deg);}
}
.spinme{
  display:inline-block;
  position:relative;
  left:0;
  top:0;
  margin:0.2rem;
  width:0.8rem;
  height:0.8rem;
  border:0.2rem solid black;
  border-radius:0%;
  outline: 1px solid rgba(0,0,0,0);
  transform:rotateZ(0deg);
  animation: spin infinite 4s;
}
.spinme:nth-of-type(2){
  outline: 1px solid transparent;
}
<div class="spinme"></div>
<div class="spinme"></div>

For those who can't test this in Internet Explorer, here is an animated .gif of the problem:

Comparison in an animated .gif

This is with transparent on the left, rgba in the middle, and both on the right.


As pointed out by @Abhitalks I misread the reference, however I will leave the below in the question to show that we've already considered this possibility, or in case something was missed/overlooked.

Thanks to @juan-c-v's answer I decided to attempt to create a test to find the computed value for transparent in each browser, and came up with the following:

$('p').text($('p').css("background-color"));
p{background-color:transparent;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p></p>

If you are viewing this in Chrome/Safari, then you will most likely see (comment if you don't) rgba(0,0,0,0). However in IE, you will probably see transparent still. I was reading the MSDN reference and found that:

The transparent keyword is not supported.

Which explains why the browsers display different results. However it doesn't explain anywhere what their version of transparent is actually defined as. I looked through the old CSS1 and CSS2 w3c specs and couldn't find an old definition. What does transparent mean?

Community
  • 1
  • 1
jaunt
  • 4,978
  • 4
  • 33
  • 54
  • 23
    Without knowing any details: That they should be equal does not mean that they are handled equally by the render engine. `transparent`existed before `rgba` was introduce, so the code responsible for `transparent` might be at another part of the code then the one handling colors. E.g. it might be that there was a flag `transparent` for elements and a color attribute and while `transparent`might omit the rendering at all, the `rgba(0,0,0,0)`might still render it but transparent. – t.niese Sep 09 '15 at 12:17
  • 4
    I've just read through the previous question. There is clearly buggy behaviour going on in at least some of the browsers here. I suggest creating a minimal test case to demonstrate the problem and submitting it to the affected browser vendors. @t.niese's comment above does sound highly plausible. – Simba Sep 09 '15 at 12:48
  • 1
    I am almost certain this is a bug in IE11 and Edge now as well. Look at [this quick fiddle](http://jsfiddle.net/2rzkn16f/) in IE11 or Edge. The wobbly element seems to also affect the other element which uses `outline-color:1px solid rgba(0, 0, 0, 0)`. It might not be just about transparent vs rgba – andyb Sep 09 '15 at 13:07
  • 1
    If you have a microsoft.com account, I would recommend submitting a bug report here: http://connect.microsoft.com/IE – Anthony Hilyard Sep 09 '15 at 13:53
  • 1
    @andyb That makes it sound like some sort of setting is toggled in IE: like when browsers enable hardware acceleration for one element but applies to all... (I believe they only use hardware acceleration when they have an indication that a DOM element would benefit from it.) This would explain t.niese's theory as well. I'll submit a report once we have a concise example: it might not just be the transparent keyword - this is just an assumption from the previous question. – jaunt Sep 09 '15 at 13:54
  • @andyb Just to add another test case in, for some reason in my IE11 they both wobble, and my eye seems to think the `transparent` one actually wobbles slightly less, but I think that's just an illusion. My version is 11.0.9600.17801 (Update Versions 11.0.19 -- kb3049563) – Adam Martin Sep 09 '15 at 16:18
  • 3
    Firefox (nightly 2015-09-09) also exhibits notable differences at the DOM level between `transparent` and `rgba(0,0,0,0)`. For example, foreground color cannot measurably be set to the zero quadruplet -- instead `node.style.color='rgba(0,0,0,0)'` immediately leads to `node.style.color==='transparent'`. Also *any* color property having a zero-alpha value becomes "computed" as `transparent` (regardless of whether all zeros) -- eg: `node.style.borderLeftColor='rgba(255,255,255,0)'` leads to `getComputedStyle(node).borderLeftColor === 'transparent'`. – humbletim Sep 09 '15 at 18:35
  • The statement of your question is not true, the linked answer uses `rgba(255, 255, 255, 0)` instead of transparent. – Etheryte Sep 11 '15 at 21:02
  • @Nit `rgba(255,255,255,0)` and `rgba(0,0,0,0)` are interchangeable as described in the other linked answer and as proven by @andyb's fiddle. Regardless you are correct, but there is little point in changing it as it does not change the question. I may do so at another stage to act as a BUMP. – jaunt Sep 11 '15 at 21:10
  • @jaunt It's not that rare of a phenomenon that the two offer different results when working with SVG so 1) that's a lead to look up (since I can't recall any specific examples off the top of my head) and 2) it's a very important detail for the question. You can't expect correct answers when you're asking the wrong question. – Etheryte Sep 11 '15 at 21:20
  • @Nit I'm not working with an SVG here, and as I just explained (as well as in the question) they are equivalent: so I'm not asking the wrong question. But for the sake of arguing I will edit the question now. – jaunt Sep 11 '15 at 21:24
  • @jaunt I don't see it stated anywhere in a spec that `rgba(255,255,255,0)` and `transparent` are equivalent or `rgba(255,255,255,0)` and `rgba(0,0,0,0)` are equivalent. – Etheryte Sep 11 '15 at 21:29
  • @Nit You are correct with that, but we get the same result using either. Hence why I'm using `rgba(0,0,0,0)` instead of `rgba(255,255,255,0)` for this question. – jaunt Sep 11 '15 at 21:41
  • This answer helps you with regarding your post. [http://stackoverflow.com/a/15958610/2632619][1] [1]: http://stackoverflow.com/a/15958610/2632619 – Andi AR Sep 14 '15 at 11:03
  • 1
    Even though @t.niese 's comment seems plausible, I still find it odd to harmonise it with the note on [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#transparent_keyword): *With the support of opacity through alpha channels, transparent was redefined as a true color in CSS Colors Level 3 allowing its use in any place where a value is required, like the color property.* Therefore, starting from CL3 I would guess that `transparent` would start to behave as a true `color` value. – Bram Vanroy Sep 17 '15 at 16:36
  • I don't have access to a machine with IE at the moment. Can you tell me if there is any difference if you were to use rgba(0%,0%,0%,0) instead of rgba(0,0,0,0) ? – zep_fan Sep 18 '15 at 00:35
  • 1
    Can it be (just speculating) that the wobble effect comes because the bounding box of the element with transparent border is uneven among the different sides, and therefor turning it around makes it wobble (the center moves). If you put two next to each other, the second one might wobble because the first one touches it and pushes it now and then. If you put a bit of space between them, would they still wobble? – Niki van Stein Sep 18 '15 at 13:08
  • @zep_fan I'm not seeing any noticeable differences, although I'm testing this on my Microsoft Surface which has less wobble anyway (for some reason...) – jaunt Sep 18 '15 at 16:28
  • @BasvanStein That makes sense although I'm curious as to why it only applies in certain circumstances... (eg IE shows the glitch, as does some version of firefox..) – jaunt Sep 18 '15 at 16:29
  • 1
    @jaunt: The MSDN reference you cited in your edit, actually means -- *The transparent keyword is not supported for Quirks Mode, IE7 Mode, and IE8 Mode (All Versions)*. It is very much supported in IE11 and Edge and does not explain the behaviour at all. – Abhitalks Sep 26 '15 at 13:40
  • @Abhitalks Ah, I was mislead by _'All Versions'_ thanks for pointing that out ;) – jaunt Sep 26 '15 at 16:42

3 Answers3

7

rgba() is a function that calculates the color and transparency for an item, it is very useful when you want to control the color and the alpha of an item, especially if you do not want to totally transparent. Being a function, you are telling the browser what color and transparency exact you want to draw the item, this is closer to JS than CSS.

On the other hand, "transparent" is a CSS property that identifies an item will be completely transparent, without making calculations of color and alpha. Being a CSS property and not a function, each browser applies it in a different way, so it would differ much to the method used by the browser to apply this property.

EDIT Ok, you say that i contradict that in my answer:

transparent

Fully transparent. This keyword can be considered a shorthand for transparent black, rgba(0,0,0,0), which is its computed value.

Well, i dont contradict that. One thing thing is the specification of the W3C standard, and another thing is the implementation of that standard by developers of different browsers. I will not break the code of IE to prove what I'm saying, because it's a bit illegal, directly ask the guys at Microsoft to see their answer.

What I've told you is that they are browsers that do not handle transparent and rgba(0, 0, 0, 0) in the same way. That's because the transparent property is much older than the rgba(0, 0, 0, 0) function (you like that more than rgba ()?), And most likely, while for IE have developed an effective method for rgba (r, g, b, a), they are still using the old method with the transparent property.

One thing you always have to keep in mind is that no web browser meets the W3C standards to 100%, that is why in most of the new property must be added the specific extension of the manufacturer (moz- webkit-, etc)

Think why it is so absurd to write the same thing four times, when everything would be solved using the standard property, and yourself will answer because it is not the same to use transparent and rgba (0, 0, 0, 0) in IE.

Juan C. V.
  • 537
  • 5
  • 19
  • Why do i have a negative vote?? can you explain that?? I've answer the question "What's the difference between rgba(0,0,0,0) and transparent?", i you give a negative vote, at least explain that – Juan C. V. Sep 18 '15 at 20:34
  • While your answer is valid, I don't think it's very useful for the issue at hand, as I'll explain now... Firstly you didn't mention `rgba(0,0,0,0)` once: you described what `rgba()` and `transparent` are, but that doesn't help solve the problem. The information in your answer is either: stated in my question or, to my knowledge (that's where references help), fictional. In addition to that, your answer is not supported by any citations and you even contradict some of the information on some of the sources that have been referenced. In future please read the whole question: not just the title. – jaunt Sep 18 '15 at 21:07
  • I readed the full question, and if you are a bit smart you can find in my answer why you have problems with the "transparent" property in IE, and why the rgba(0,0,0,0) (or whatever rgba(R, G, B, 0) function, because the last 0 will always make it transparent) will fix the problem. Sometimes its no needed so many code, and too many words to explain a simple thing. So i will resume for you my answer: transparent and rgba(R, G, B, 0) will give you a transparent item, but not by the same method, thats why you dont have the same result in IE; the method for transparent in IE is a s**t. – Juan C. V. Sep 18 '15 at 21:30
  • PD, i dont mention rgba(0, 0, 0, 0) because i was thinkin that smart people will understand that rgba() is the short for rgba(r, g, b, a) function. And its no necesary to make rgba(0, 0, 0, 0) for a transparent item, rgba(255, 255, 255, 0) will also be transparent – Juan C. V. Sep 18 '15 at 21:33
  • Thank you for rewriting your answer, I understand what you mean more clearly now. Hahaha I agree with IE being bad ;) That's actually highlighted a few things I took for granted. I completely overlooked that the standards aren't all met by the browser... I'll look into, thanks for that :) – jaunt Sep 18 '15 at 22:16
  • 1
    You are welcome. The problem is always IE, making the web designers life more difficult each day, hahaha – Juan C. V. Sep 18 '15 at 22:43
  • While this answer doesn't provide a solution, it is very useful and, as a result, I found that IE's definition of `transparent` is different - hence the different rendering properties. Awarded bounty ;) – jaunt Sep 19 '15 at 20:33
6

I've been trying your code for the value transparent in Chrome, installed on a laptop running Windows 7 OS.

I'm not getting any wobble whatsoever myself. So I expect this issue is specific for certain browsers and operating systems based on how that specific browser and OS decide to render your element.

This issue could be related to whether or not your browser uses hardware acceleration. Now, there is a trick to force your browser to use hardware acceleration : make your browser think that a 3D transformation is being applied to an element.

You could to that by adding the following properties to your element :

.fake3Dtransformation {
   -webkit-transform: translate3d(0, 0, 0);
   -moz-transform: translate3d(0, 0, 0);
   -ms-transform: translate3d(0, 0, 0);
   transform: translate3d(0, 0, 0);
  /* Other transform properties here */
}

While I'm not entirely sure if this will fix the wobbling issue when using transparent (as I'm not able to reproduce the issue), applying this "hack" should in theory always give you the smoothest rendering. Check out eg. this article for more information.

So for your demo code, you'd end up with this :

@keyframes spin{
    0% {transform:rotateZ(0deg);}
    50% {transform:rotateZ(360deg);border-radius:60%;}
    100%{transform:rotateZ(720deg);}
}
#spinme{
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    display:inline-block;
    position:relative;
    left:0;
    top:0;
    margin:0.2rem;
    width:0.8rem;
    height:0.8rem;
    border:0.2rem solid black;
    border-radius:0%;
    outline: 1px solid rgba(0,0,0,0);
    animation: spin infinite 4s;
}

#spinme:nth-of-type(2){
    outline: 1px solid transparent;
}
<div id="spinme"></div>
<div id="spinme"></div>

THE FIDDLE :

https://jsfiddle.net/z2r7ypy7/4/

John Slegers
  • 45,213
  • 22
  • 199
  • 169
  • You don't see it wobble because you need the `@-moz-` etc stuff in front of it to make it work to all browsers. – Niki van Stein Sep 17 '15 at 15:54
  • Chrome (and apparently Safari) are producing the expected result. Try testing it in Internet Explorer, I'll update my question to specifically mention IE :) I hadn't thought of forcing hardware acceleration in this case so good shout! – jaunt Sep 17 '15 at 16:29
3

In my opinion, it is not good to use the same id twice, whatever you are doing, it is meant as an identifier. I also do not find it weird that they both show the animation, since both of them have the same id that match the animation in the css.

#spinme{
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    display:inline-block;
    position:relative;
    left:0;
    top:0;
    margin:0.2rem;
    width:0.8rem;
    height:0.8rem;
    border:0.2rem solid black;
    border-radius:0%;
    outline: 1px solid rgba(0,0,0,0);
    transform:rotateZ(0deg);

}

#spinme:nth-of-type(1){
    animation: spin infinite 4s;
}

if you do this, only one wobbles, and it makes perfect sense to me. Perhaps it does not answer your question about the transparent issue, but I am not sure if that is really the issue anyways.

edit No matter which color I try, transparent or rgba(0,0,0,0) in any combination they both animate on Safari.

Niki van Stein
  • 10,564
  • 3
  • 29
  • 62
  • Good shout with the `id` attribute, although after changing it to `class` there is no change: the problem remains. It's not about whether they animate or not, its the fact that one wobbles. This mainly happens on Internet Explorer, although other users have told us that it happens on some versions of Firefox so I didn't mention Internet Explorer in the question. Both Chrome and Safari use `webkit` so it makes sense that they produce the same result (without wobble). I don't understand you code, only one of them will animate which defeats the point, no? – jaunt Sep 17 '15 at 16:26
  • 1
    Aaah now I mean what you mean with wobbles.. my apologies it was not clear to me and I missed the detail in the gif. That looks like an IE bug for sure yes. – Niki van Stein Sep 17 '15 at 16:43