Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text CSS Rendering Performance : RGBA vs HEX vs OPACITY

A designer always provides CSS using opacity rather than actual color values. Does this affect rendering performance in the browser?

Which renders faster, on an always white background, where I don't actually care about transparency.

<span>Hello</span> 
  1. span {color: black; opacity: 0.7;}
  2. span {color: rgba(0, 0, 0, 0.7);}
  3. span {color: #b3b3b3;}

My gut says opacity is slower (despite being put in the GPU) as now at render time the browser has to take into account the background, so any changes will cause it to repaint the object because of this transparency, while a statically colored object will never change.

like image 236
simbolo Avatar asked Jul 22 '16 10:07

simbolo


People also ask

What's the difference between using opacity and RGBA transparency in CSS?

Opacity sets the opacity value for an element and all of its children; While RGBA sets the opacity value only for a single declaration.

Why do we use opacity in CSS?

The CSS opacity property is used to specify the transparency of an element. In simple word, you can say that it specifies the clarity of the image. In technical terms, Opacity is defined as degree in which light is allowed to travel through an object.

How do I make Rgba transparent?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

What is alpha transparency CSS?

Transparency using RGBA The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter.


1 Answers

I've just made a simple HTML containing around 50k lines of span.

Then I used Google performance option to check the rendering progress.

Using span {color: black; opacity: 0.7;} :

enter image description here

Using span {color: rgba(0, 0, 0, 0.7);} :

enter image description here

And finally using span {color: #b3b3b3;} :

enter image description here

So, as you've guessed, using opacity is slower by a fair margin.

like image 189
Alvaro Menéndez Avatar answered Oct 09 '22 17:10

Alvaro Menéndez