Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG fill color transparency / alpha?

Is it possible to set a transparency or alpha level on SVG fill colours?

I've tried adding two values to the fill tag (changing it from fill="#044B94" to fill="#044B9466"), but this doesn't work.

like image 780
Ollie Glass Avatar asked May 18 '11 09:05

Ollie Glass


2 Answers

You use an addtional attribute; fill-opacity: This attribute takes a decimal number between 0.0 and 1.0, inclusive; where 0.0 is completely transparent.

For example:

<rect ... fill="#044B94" fill-opacity="0.4"/> 

Additionally you have the following:

  • stroke-opacity attribute for the stroke
  • opacity for the entire object
like image 154
Williham Totland Avatar answered Oct 02 '22 02:10

Williham Totland


As a not yet fully standardized solution (though in alignment with the color syntax in CSS3) you can use e.g fill="rgba(124,240,10,0.5)". Works fine in Firefox, Opera, Chrome.

Here's an example.

like image 37
Erik Dahlström Avatar answered Oct 02 '22 04:10

Erik Dahlström