Menu

HEX to Unity Color Converter

Convert any HEX color to Unity Color and Color32 C# code with alpha. Copy-ready for scripts, materials, UI, and both Gamma and Linear color spaces.

#22C55E
R 34
G 197
B 94

HEX input

Alpha

1.00

Color space

Color (float) — Unity

        
Color32 (byte) — Unity

        
Runtime parsing — ColorUtility

        
Reusable HexToColor extension

        
ColorPalette static class

        

Saved swatches

No saved swatches yet. Save a color to compare HEX, RGB, and alpha across multiple shades.

What is a HEX to Unity Color converter?

A HEX to Unity color converter turns a CSS-style HEX color into Unity C# code. Unity has no built-in HEX color type, so the converter splits the HEX into red, green, and blue bytes, divides each by 255, and writes the exact new Color(r, g, b, a) call you can paste into a MonoBehaviour or a static palette class. This tool also outputs Color32 for byte-precision work, ColorUtility.TryParseHtmlString for runtime parsing, a reusable HexToColor extension, and a gamma/linear toggle for correct color space handling.

Key takeaways

  • Unity has no HEX color literal — colors are always RGB floats or bytes.
  • Color uses floats 0–1; Color32 uses bytes 0–255.
  • Use ColorUtility.TryParseHtmlString() for runtime HEX parsing.
  • Linear color space requires different values than Gamma for the same HEX.
  • This tool copies Color, Color32, ColorUtility, and helper code.
  • Every output is sRGB-correct and includes alpha.

Built and maintained by the BestColorPicker team. Last updated .

How to use the HEX to Unity color converter

Every output updates live. Copy any block straight into your C# script or palette file.

  1. Enter your HEX colorType or paste a HEX code, or use the color picker. 3-digit, 6-digit, and 8-digit HEX are all supported, with or without the leading hash.
  2. Adjust alpha if neededDrag the alpha slider or enter a value from 0 to 1. Every Unity output updates to include the alpha component.
  3. Choose gamma or linear modeUnity projects can use Gamma or Linear color space. Toggle the switch to see the correct Color struct values for your project settings.
  4. Copy the C# codeSelect Copy on any block. The tool copies clean, compilable C# with correct float precision and the alpha component included.
  5. Use the helper utilityIf you prefer runtime HEX parsing, copy the ColorUtility.TryParseHtmlString example or the reusable HexToColor extension.
  6. Save and compare colorsSave colors to a strip to compare how the same HEX looks in your project across multiple alpha values, then export the strip as JSON.

Unity Color vs Color32 vs ColorUtility

Unity offers several ways to represent the same color. Pick the right one for the job.

ApproachType / APIBest for
Float colornew Color(r, g, b, a)Materials, shaders, UI Image, line renderer, most runtime APIs
Byte colornew Color32(r, g, b, a)Vertex colors, textures, per-pixel data, arrays of colors
Runtime parseColorUtility.TryParseHtmlString("#HEX", out Color c)User data, config files, asset HEX strings
Static paletteStatic class with Color fieldsDesign systems, brand colors, shared tokens
ScriptableObjectSO with serialized Color fieldsDesigner-editable palettes without code changes

Gamma vs Linear color space

Unity projects use one of two color spaces, and it changes how HEX colors are rendered. Gamma space treats sRGB values directly as light intensity. Linear space converts sRGB to linear light before shading, which is physically correct and required for modern PBR rendering. If your project uses URP or HDRP, it is almost certainly Linear.

The toggle in this tool shows the values that match each project setting. For most modern Unity projects, the sRGB HEX value is still the source of truth — the toggle is there to make the difference visible.

Runtime HEX parsing with ColorUtility

If the HEX string comes from user data, config files, or an asset, use ColorUtility.TryParseHtmlString. It handles 3-, 6-, and 8-digit HEX with or without the hash, and it returns a bool so you can fall back to a default color on bad input.

if (ColorUtility.TryParseHtmlString("#FF5733", out var color)) {
    image.color = color;
} else {
    image.color = Color.magenta;
}

Avoid calling this in Update() or in jobs. Parse once at load time and cache the result.

Why use a static palette class

Hard-coded colors scattered across files are one of the most common sources of maintainability problems in Unity projects. A central palette class gives you:

The ColorPalette output in this tool is a ready-to-paste class with the current color pre-filled. Add more fields as your palette grows.

Common mistakes

Frequently asked questions

How do I convert HEX to Unity Color in C#?

Convert HEX to RGB floats: split the HEX into red, green, and blue bytes, divide each by 255, and pass them to new Color(r, g, b, a). For example, #FF5733 becomes new Color(1f, 0.341f, 0.2f, 1f). This converter outputs the exact line to paste into a C# script.

What is the difference between Color and Color32 in Unity?

Color uses float components from 0 to 1 and is the standard type for materials, shaders, and most Unity APIs. Color32 uses byte components from 0 to 255 and is more memory-efficient for textures, vertex colors, and per-pixel data. Both represent the same color.

How do I parse a HEX string at runtime in Unity?

Use ColorUtility.TryParseHtmlString("#FF5733", out Color color). It returns a bool and supports 3-, 6-, and 8-digit HEX with or without the hash. It does not work in the Unity editor for asset colors set in the inspector, so use ColorUtility or hard-coded Color literals.

What is the difference between linear and gamma color space in Unity?

Gamma space treats sRGB values directly as light intensity, which looks fine for simple projects but is physically incorrect. Linear space converts sRGB values to linear light before rendering, which is required for physically based rendering, correct lighting, and modern Unity projects. The Color struct values can differ between the two spaces when you author HEX colors.

Why does my Unity color look different from the design tool?

Two common causes. First, color space: if your Unity project uses Linear color space, HEX colors are converted to linear light and rendered differently. Second, sRGB toggle on textures: a texture marked sRGB will be gamma-corrected twice if you also convert to linear in code. Match the tool's output to your project color space and toggle sRGB on textures correctly.

Should I use new Color() or ColorUtility.TryParseHtmlString()?

Use new Color() when the color is known at compile time. It is faster, has no parsing overhead, and works in jobs and ECS. Use ColorUtility.TryParseHtmlString() when the color comes from user data, a config file, or an asset that stores HEX strings.

How do I set a Unity color from HEX without writing code?

Use a Material property, a UI Image color picker in the Inspector, or paste the HEX into the color field. Unity's color picker accepts HEX directly and converts to Color internally. For runtime Hex parsing, use ColorUtility.TryParseHtmlString.

What is the HEX format Unity accepts?

ColorUtility.TryParseHtmlString accepts "#RRGGBB", "#RRGGBBAA", "#RGB", and "#RGBA" with or without the leading hash. Alpha in 8-digit HEX is stored as the last byte.

Does Unity support oklch or oklab colors?

Not natively. Unity's Color type is sRGB float values. To use OKLCH, convert to sRGB first with a tool like the OKLab Color Converter, then pass the RGB values to Unity.

Is the HEX to Unity Color converter free?

Yes. The tool is free, needs no account, and runs entirely in your browser. Your colors are never uploaded.

Can I use this for Unity UI (Canvas) colors?

Yes. UI Image and Text colors use the same Color struct, so you can paste the output into Image.color or Text.color. For vertex-colored UI, use Color32 for efficiency.

How do I make a Unity color from HEX that works in HDRP or URP?

The Color value is the same in HDRP, URP, and Built-in as long as the color space setting matches. For HDR colors, multiply the RGB channels by an intensity value after creating the color.

More color tools

Sources and further reading