Search code examples
javascriptcolorshextransparencybackground-color

Add opacity to hex representation of color


I have a color code, for example #EB5757 which is a kind of red. I want to add opacity to it 0.15 or 15%. After looking on this question I saw in the accepted answer that for 15% one must add 26 at the beginning.

So I did it: #26EB5757 but now the resulted color is not a red with opacity but a green. I'm using this in Javascript/React if this information is useful.

style = {backgroundColor: '#26EB5757'}

Any ideas on how to set that original red color to be opaque?


Solution

  • 8 digit hexadecimal color notation in CSS has the following format:

    #RRGGBBAA
    
    RR - red
    GG - green
    BB - blue
    AA - alpha
    

    You should use:

    #EB575726 (for your 15% red)