Skip to main content
conversion

RGB to Hex Converter

Convert RGB (Red, Green, Blue) color values to a hexadecimal color code. Enter individual R, G, B channel values (0-255) and get the hex string for CSS and design tools.

Reviewed by Christopher FloiedPublished Updated

This free online rgb to hex converter provides instant results with no signup required. All calculations run directly in your browser — your data is never sent to a server. Enter your values below and see results update in real time as you type. Perfect for everyday calculations, homework, or professional use.

Range: 0 – 255

Red channel intensity (0-255)

Range: 0 – 255

Green channel intensity (0-255)

Range: 0 – 255

Blue channel intensity (0-255)

Results

Hex Color Code

#4285F4

Relative Luminance

126.8

How to Use This Calculator

1

Enter your input values

Fill in all required input fields for the RGB to Hex Converter. Most fields include unit selectors so you can work in your preferred unit system — metric or imperial, whichever matches your problem.

2

Review your inputs

Double-check that all values are correct and that you have selected the right units for each field. Incorrect units are the most common source of calculation errors and can produce results that are off by factors of 2, 10, or more.

3

Read the results

The RGB to Hex Converter instantly computes the output and displays results with units clearly labeled. All calculations happen in your browser — no loading time and no data sent to a server.

4

Explore parameter sensitivity

Try adjusting individual input values to see how the output changes. This is a quick and effective way to develop intuition about how different parameters influence the result and to identify which inputs have the largest effect.

When to Use This Calculator

  • Use the RGB to Hex Converter when you need accurate results quickly without the risk of manual computation errors or unit conversion mistakes.
  • Use it to verify calculations made by hand or in spreadsheets — an independent check can catch errors before they lead to costly decisions.
  • Use it to explore how changing input parameters affects the output — a quick way to develop intuition and identify the most influential variables.
  • Use it when collaborating with others to ensure everyone is working from the same numbers and applying the same assumptions.

Related Calculators

About RGB to Hex Converter

The RGB to Hex Converter transforms Red, Green, and Blue color channel values into the standard hexadecimal color code used in web development and design. RGB values are commonly provided by color pickers, image editing software, and accessibility audit tools, while hex codes are the preferred notation for CSS stylesheets, HTML attributes, and design specifications. This converter accepts three integer values from 0 to 255 and produces a six-digit hex string prefixed with #. It also calculates the relative luminance, which is useful for checking color contrast compliance with WCAG accessibility guidelines.

The Math Behind It

Converting RGB to hexadecimal involves converting each decimal channel value (0-255) into a two-digit base-16 representation. The hex digits are 0-9 and A-F, where A=10, B=11, C=12, D=13, E=14, F=15. To convert a decimal value to hex, divide by 16: the quotient is the first digit and the remainder is the second digit. For example, decimal 180 divided by 16 gives quotient 11 (hex B) and remainder 4, so 180 in hex is B4. Values below 16 require a leading zero: decimal 9 becomes 09 in hex. The three hex pairs are concatenated as RRGGBB and prefixed with #. This produces codes like #4285F4 (Google blue), #FFFFFF (white), and #000000 (black). Relative luminance measures the perceived brightness of a color on a 0-255 scale (before gamma correction). The formula weights green heavily because human eyes are most sensitive to green light. Full luminance calculation for WCAG contrast ratios requires gamma correction: linearise each channel as C_lin = (C/255)^2.2, then compute L = 0.2126*R_lin + 0.7152*G_lin + 0.0722*B_lin. The hex color system has been part of web standards since HTML 2.0 in 1995. CSS3 extended it with rgba(), hsla(), and eight-digit hex (with alpha channel). Despite the availability of these alternatives, six-digit hex remains the most widely used color notation in practice. Design systems and style guides typically specify brand colors in hex format for consistency across platforms. When implementing designs, converting between RGB and hex is a daily task for front-end developers.

Formula Reference

RGB to Hex Conversion

hex = '#' + toHex(R) + toHex(G) + toHex(B)

Variables: R, G, B = channel values 0-255, toHex() = convert decimal to 2-digit hexadecimal

Worked Examples

Example 1: Convert RGB(66, 133, 244) to Hex

A design spec provides a blue color as RGB(66, 133, 244). Convert to hex.

Step 1:Red: 66 / 16 = 4 remainder 2 => 42
Step 2:Green: 133 / 16 = 8 remainder 5 => 85
Step 3:Blue: 244 / 16 = 15 remainder 4 => F4
Step 4:Combine: #4285F4

RGB(66, 133, 244) = #4285F4

Example 2: Convert Pure White RGB(255, 255, 255)

Verify that white converts correctly.

Step 1:Red: 255 / 16 = 15 remainder 15 => FF
Step 2:Green: 255 => FF
Step 3:Blue: 255 => FF
Step 4:Combine: #FFFFFF

RGB(255, 255, 255) = #FFFFFF (white).

Common Mistakes & Tips

  • !Entering RGB values outside the 0-255 range. Values below 0 or above 255 are invalid and must be clamped.
  • !Forgetting to pad single-digit hex values with a leading zero. Decimal 9 must become '09', not '9', to maintain six digits.
  • !Swapping the channel order. RGB to hex always produces RRGGBB format, not BBGGRR.

Related Concepts

Hex to RGB Converter

The reverse conversion: decompose a hexadecimal color code into its red, green, and blue component values.

HSL Color Model

An alternative color representation using Hue, Saturation, and Lightness, which is often more intuitive for selecting and adjusting colors than RGB.

Used in These Calculators

Calculators that build on or apply the concepts from this page:

Frequently Asked Questions

Can I get an 8-digit hex code with alpha transparency?

This converter produces 6-digit hex codes without alpha. To add transparency, append two more hex digits for the alpha channel (00 = fully transparent, FF = fully opaque). For example, #4285F480 is 50% transparent.

What is relative luminance used for?

Relative luminance measures perceived brightness and is used to calculate contrast ratios for WCAG accessibility compliance. A contrast ratio of at least 4.5:1 is required for normal text.

Are uppercase and lowercase hex codes different?

No. Hex codes are case-insensitive: #4285F4 and #4285f4 are identical. Convention varies, but uppercase is common in design tools while lowercase is common in CSS.

Embed this calculator on your site

Paste this snippet into your blog, course page, or documentation to drop a live, interactive RGB to Hex Converter into your page.

Free to embed — includes a link back to MegaCalc.