How to use the RGB percentage converter
- Enter the Colour as HEX, rgb(), hsl(), oklch(), a CSS name or with the picker.
- Read Percentage rgb() for CSS, and 0–1 floats for code.
- Copy 8-bit integers or 16-bit integers if your tool uses whole numbers.
- Copy the GLSL, Swift (UIColor) or Unity (Color32) line into your project.
What it does and when to use it
The same colour is written differently in almost every environment. CSS accepts HEX, 0–255 or percentages. Shaders and many graphics APIs want 0–1 floats. Apple’s UIColor takes 0–1 values, Unity’s Color32 takes bytes, and some image pipelines use 16-bit channels. Converting by hand is slow and error-prone, especially the division by 255.
This converter gives every common form at once. It is handy for game developers moving a palette from a design tool into a shader, iOS developers turning a brand HEX into UIColor code, and anyone writing rgb() with percentages. For other CSS notations such as HSL, OKLCH and Lab, use the colour converter. For HEX shorthand, see the HEX shorthand expander, and for print-style values, the CMYK to RGB converter.
How it works
The colour is read and limited to the sRGB range, so out-of-gamut input from oklch() or lab() is clipped. With each channel c as a 0–1 value:
- percentage = c × 100, shown to one decimal
- float = c, shown to three decimals
- 8-bit = round(c × 255)
- 16-bit = round(c × 65535)
The code lines are built from the floats or the 8-bit values, with alpha added at the end.
Worked examples
These are the converter’s own outputs.
Blue #3b82f6. Percentage rgb(): rgb(23.1%, 51%, 96.5%). Floats 0.231, 0.51, 0.965. GLSL vec4(0.231, 0.51, 0.965, 1); Swift UIColor(red: 0.231, green: 0.51, blue: 0.965, alpha: 1); Unity new Color32(59, 130, 246, 255).
White #ffffff. rgb(100%, 100%, 100%), floats 1, 1, 1, 16-bit 65535 on each channel.
A translucent percentage colour. rgb(50% 25% 0% / 0.5) gives 8-bit 128, 64, 0, HEX #80400080 and Unity new Color32(128, 64, 0, 128).
Limits and tips
- Floats are rounded for display; three decimals are enough to rebuild the 8-bit colour.
- Wide-gamut colours are clipped, not gamut-mapped. Use the OKLCH converter to see the mapped sRGB value first.
- Everything runs in your browser.
Frequently asked questions
How do I convert a HEX colour to 0–1 values?
Are the float values precise enough for shaders?
Why do I need 16-bit values?
Do the code snippets include alpha?
Do the values use linear or gamma-encoded RGB?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.