Colour Picker & Converter · Tutorial
How to add transparency to a HEX colour in CSS
5 min readbeginnerUpdated
You have a brand colour as a HEX code and need a 15% tint of it for a hover background or a translucent overlay. This tutorial converts the code to RGB, writes the transparent version three ways, and explains which to use.
What you need
- The Colour Picker & Converter
- Your HEX colour, or the sample from the Try it button
Steps
Convert the code
Type the HEX code into the converter. The sample
#1DA1F2becomesrgb(29, 161, 242). The RGB fields below show the three numbers separately: 29, 161 and 242.Write it with rgba()
Add a fourth value for opacity, from 0 (invisible) to 1 (solid). A light hover background might use 15%. This works in every browser.
.button:hover { background: rgba(29, 161, 242, 0.15); }Or use an 8-digit HEX code
Modern browsers also accept opacity as two extra HEX digits. 15% of 255 is about 38, which is
26in HEX, so the colour becomes#1DA1F226. It’s compact but harder to read.Or keep one variable with color-mix()
If your colour is a CSS variable, newer browsers can make the transparent version for you, so you never repeat the numbers.
:root { --brand: #1da1f2; } .button:hover { background: color-mix(in srgb, var(--brand) 15%, transparent); }Check readability
A transparent colour looks different on every background. If text sits on top, check the result in the Colour Contrast Checker with the real background.
Try it yourself
Opens the Colour Picker & Converter with this tutorial's sample loaded.
Common mistakes
- Using 0 to 255 for opacity
- In
rgba(), opacity is a decimal from 0 to 1 (or a percentage), not a number up to 255.rgba(29, 161, 242, 38)is fully opaque. - Using opacity on the element
opacity: 0.15makes the text and everything inside transparent too. Use a transparent background colour instead.- Forgetting the
- The converter accepts codes without #, but CSS needs it: write
#1da1f2, not1da1f2.
Next steps
Go back to the Colour Picker & Converter, or keep going with one of these:
FAQ
Is rgba() still needed, or is rgb() enough?
Modern browsers accept a fourth value in rgb() too, like rgb(29 161 242 / 15%). rgba() still works everywhere, so either is fine.
How do I convert RGB back to HEX?
Type the three numbers into the RGB fields; the HEX code updates.