RGB to Hex Converter

Convert RGB color values to hexadecimal color codes with live preview

RGB Values

#3498DB

Hex Result

Hexadecimal Color Code

#3498DB

All Color Formats

Hex#3498DB
RGBrgb(52, 152, 219)
HSLhsl(204, 70%, 53%)
CMYKcmyk(76%, 31%, 0%, 14%)

CSS Code

background-color: #3498DB;

color: rgb(52, 152, 219);

What is RGB to Hex Conversion?

RGB to hex conversion transforms color values from the RGB (Red, Green, Blue) color model into hexadecimal color codes used in web design and digital graphics. Every color displayed on a screen is composed of red, green, and blue light mixed together. Each channel ranges from 0 (no intensity) to 255 (full intensity), creating over 16.7 million possible colors. The hex format condenses these three numbers into a compact six-character string preceded by a hash symbol.

The hexadecimal system uses base-16 notation, which means each color channel is represented by exactly two hex digits (00 to FF). For example, pure red is RGB(255, 0, 0) which converts to #FF0000. White is RGB(255, 255, 255) or var(--card-bg)FFF, and black is RGB(0, 0, 0) or var(--foreground)000. The hex format became the standard for web colors because it is more compact than the rgb() notation and is universally supported by HTML, CSS, and virtually all graphics software.

This converter goes beyond simple RGB-to-hex translation. It also computes the HSL (Hue, Saturation, Lightness) and CMYK (Cyan, Magenta, Yellow, Key/Black) representations of your color, providing a complete color profile. A live preview swatch shows the actual color, and CSS code snippets are generated for immediate use in your projects.

The RGB to Hex Formula

Converting an RGB value to hexadecimal requires expressing each channel (0–255) as a two-digit base-16 number. The conversion uses integer division and modulo arithmetic.

RGB to Hex Conversion

Hex = # + (R₁R₀)(G₁G₀)(B₁B₀) where each pair is the hex representation of 0–255

Where:

  • R= Red channel value (0–255)
  • G= Green channel value (0–255)
  • B= Blue channel value (0–255)
  • #= Hash prefix indicating a hex color code

Understanding Color Models

Different color models serve different purposes. The RGB model is additive — colors are created by mixing light. Starting from black (no light), adding red, green, and blue produces brighter colors, culminating in white when all three are at maximum. This model is used for screens, monitors, and digital displays.

The HSL model describes color in terms of hue (the color itself, 0°–360°), saturation (how vivid the color is, 0%–100%), and lightness (how light or dark, 0%–100%). HSL is more intuitive for humans because you can think of it as "what color, how colorful, how bright." The CSS hsl() function uses this model directly.

The CMYK model is subtractive — it starts with white paper and adds ink to absorb light. It is used for print media. Cyan, magenta, and yellow pigments absorb specific wavelengths; black (key) is added for deep shadows. Converting RGB to CMYK is essential for designers who create digital artwork that will be printed.

How to Use This Calculator

Enter your RGB values to get a complete color profile:

  1. Adjust the Red slider: Set the red channel from 0 to 255 using the slider or number input.
  2. Adjust the Green slider: Set the green channel value.
  3. Adjust the Blue slider: Set the blue channel value.
  4. View the Hex Result: The hex code appears instantly in the result card, along with a live color preview swatch.
  5. Copy CSS Code: The generated CSS code block provides ready-to-use background-color and color declarations.

The "All Color Formats" section shows your color in hex, RGB, HSL, and CMYK simultaneously, making it easy to use the format appropriate for your project.

Real-World Applications

Web development and CSS styling relies heavily on hex color codes. Every background, text color, border, and shadow in a stylesheet uses hex or RGB values. Designers create color palettes with specific hex codes to maintain brand consistency across pages. Tools like this converter help translate colors from design mockups into working code.

Brand identity and marketing require precise color matching. Companies like Tiffany & Co. (Tiffany Blue, #0ABAB5) and Coca-Cola (Coca-Cola Red, #F40009) have trademarked specific colors. Converting between RGB and hex ensures these colors render identically across different platforms and media.

Digital art and graphic design use these conversions when working between software. An artist might pick a color in Photoshop (which displays RGB values) and need the hex code for a web stylesheet. Similarly, converting to CMYK is necessary when preparing digital artwork for professional printing.

Worked Examples

Converting Pure Blue to Hex

Problem:

Convert RGB(0, 0, 255) to hexadecimal.

Solution Steps:

  1. 1Red channel: 0 in decimal = 00 in hex
  2. 2Green channel: 0 in decimal = 00 in hex
  3. 3Blue channel: 255 in decimal = FF in hex (16×15 + 15 = 255)
  4. 4Concatenate with hash prefix: var(--foreground)0FF

Result:

var(--foreground)0FF (pure blue)

Converting a Custom Color

Problem:

Convert RGB(52, 152, 219) to hex and find its HSL equivalent.

Solution Steps:

  1. 1Red: 52 = 34 in hex (3×16 + 4 = 52)
  2. 2Green: 152 = 98 in hex (9×16 + 8 = 152)
  3. 3Blue: 219 = DB in hex (13×16 + 11 = 219)
  4. 4Hex result: #3498DB
  5. 5HSL calculation: Hue ≈ 204°, Saturation ≈ 70%, Lightness ≈ 53%

Result:

#3498DB — hsl(204, 70%, 53%)

Converting from Hex to RGB

Problem:

Convert #2ECC71 back to RGB values.

Solution Steps:

  1. 1Red: 2E = 2×16 + 14 = 46
  2. 2Green: CC = 12×16 + 12 = 204
  3. 3Blue: 71 = 7×16 + 1 = 113
  4. 4RGB result: (46, 204, 113)

Result:

RGB(46, 204, 113) — a vibrant green

Tips & Best Practices

  • Memorize common hex values: var(--foreground)000 (black), var(--card-bg)FFF (white), #FF0000 (red), #00FF00 (green), var(--foreground)0FF (blue)
  • Use shorthand hex codes (#RGB) when all channel digits are doubles (#FF0000 can be written as #F00)
  • The first two hex digits control red, the middle two control green, the last two control blue
  • For web accessibility, ensure sufficient contrast between text and background colors (WCAG recommends 4.5:1 ratio)
  • CMYK values are essential when preparing designs for professional printing — RGB screens and print use different color models
  • Use HSL when you want to create color variations (lighter, darker, more saturated) from a base color

Frequently Asked Questions

The # symbol is a prefix that tells browsers, design tools, and code editors that the following six characters represent a hexadecimal color code. It is not part of the color value itself but serves as a universal indicator. In CSS, you can write either #FF0000 or rgb(255, 0, 0) to represent the same red color.
Hexadecimal is more compact for representing color values. Each RGB channel (0–255) maps to exactly two hex digits (00–FF), so a complete color is just six characters. Hex also aligns neatly with the 8-bit color channel structure, making it easier for developers to read and remember color codes at a glance.
RGB describes a color by how much red, green, and blue light to combine (additive model), while HSL describes it by hue (the actual color on the color wheel), saturation (vividness), and lightness (brightness). HSL is often more intuitive for humans because you can think in terms of 'a slightly lighter, less saturated version of blue' rather than adjusting three separate channel numbers.
Yes, every valid six-digit hex code corresponds to exactly one RGB color. The conversion is deterministic: each pair of hex digits maps to a decimal value between 0 and 255. Some hex codes also support a shorthand three-digit form (#RGB) where each digit is doubled: #F0A becomes #FF00AA.
A standard six-digit hex code can represent 16,777,216 colors (256 × 256 × 256 = 16,777,216). This is because each of the three channels has 256 possible values (00 to FF in hex). This is often called 'True Color' and is sufficient to display photographs and complex gradients without visible banding.

Sources & References

Last updated: 2026-06-06

💡

Help us improve!

How would you rate the RGB to Hex Converter?

<>

Editorial Note

MyCalcBuddy Editorial Team

This page is maintained as an educational calculator reference.

Source

Formula Source: NIST Guide to SI Units

by National Institute of Standards

UpdatedLast reviewed: May 2026
CheckedFormula checks are based on standard references and internal QA review.