RGB percentage converter — HEX to percent, 0–1 floats, GLSL, Swift and Unity

Enter any colour and get its red, green and blue values as percentages, 0–1 decimals, 8-bit and 16-bit integers, and as GLSL, Swift and Unity code you can paste straight in.

Live demo · real result from this tool
Percentage rgb()rgb(23.1%, 51%, 96.5%)
0–1 floats
0.231, 0.51, 0.965
8-bit integers
59, 130, 246
16-bit integers
15163, 33410, 63222
GLSL
vec4(0.231, 0.51, 0.965, 1)
Swift (UIColor)
UIColor(red: 0.231, green: 0.51, blue: 0.965, alpha: 1)
Unity (Color32)
new Color32(59, 130, 246, 255)
HEX
#3b82f6

Colours

Processed on your device — nothing is uploaded.

How to use the RGB percentage converter

  1. Enter the Colour as HEX, rgb(), hsl(), oklch(), a CSS name or with the picker.
  2. Read Percentage rgb() for CSS, and 0–1 floats for code.
  3. Copy 8-bit integers or 16-bit integers if your tool uses whole numbers.
  4. 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?
Convert each pair to a number from 0 to 255, then divide by 255. For
Are the float values precise enough for shaders?
They are rounded to three decimals, which is finer than one step of an 8-bit channel (1/255 is about 0.0039), so the colour comes back to the same 8-bit value. For exact maths in code, divide the 8-bit integers by 255 yourself.
Why do I need 16-bit values?
Some image formats, video tools and colour APIs use 0–65535 channels. Each value here is the 0–1 float times 65535, rounded. For
Do the code snippets include alpha?
Yes. GLSL vec4 and Swift UIColor end with alpha from 0 to 1, and Unity Color32 ends with alpha from 0 to 255. A colour typed with transparency, such as rgb(50% 25% 0% / 0.5), keeps it.
Do the values use linear or gamma-encoded RGB?
Gamma-encoded sRGB, the same values as the HEX code. If your shader or engine works in linear colour, convert them with the sRGB transfer function first.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close