RGBa Generator

Transform any CSS colour into RGBa

Have you ever needed to subtract a specific value from a colour, e.g. only the reds? Have you ever wanted to convert a solid colour to one with an alpha component?
Or maybe the other way 'round: remove that alpha component? Enter RGBa Generator! You can convert any valid CSS colour to RGB.
That means: RGB, RGBa, HSL, HSLa, colour names and HEX values. And all that for a file of less than 700 bytes!

To list the things you can do: you can convert any colour to RGB(a), you can add or remove alpha components and you can export any colour as an RGB object.
Note that jQuery is required. Examples are given below.

How to use

1. Download the latest version from the GitHub page. Use the minified version on production sites! The expanded version is suited for debugging and development only.

2. Include the plug-in on your web page. Make sure that you include the script after loading jQuery.

If, on the other hand, you want to add an alpha channel, you can do so by setting addAlpha to any value between 0 and 1. When the input is a non-transparent colour, the alpha value will be added. If it is a transparent one, the provided value will overwrite the alpha component of the input.

On a final note, it is important to realise that when no colour is specified, the plugin won't return anything, i.e. undefined.

Try it yourself!

HSL(a), RGB(a), HEX or colour name

(Optional) a value between zero and one

Remove alpha value?

Output as object?

What part of object?

Result

Input:

Output:

Got a question? Shoot!

If you have any questions, feedback, comments, improvements or requests: add an issue on GitHub. If you don't have a GitHub account, or you just want to say hi, you can always hit me up on Twitter as well!