RGB to Hex Converter

Convert RGB color values to hexadecimal color codes for CSS and HTML. Enter red, green, and blue values to get the hex code.

%
#2ECC71
Hex (6-digit)
#2ECC71
Standard web color notation
Hex (8-digit)
#2ECC71FF
Includes alpha transparency channel
CSS RGB
rgb(46, 204, 113)
CSS function notation for stylesheets
CSS HSL
hsl(145, 63%, 49%)
Hue 145deg, Sat 63%, Light 49%
Brightness
146.4
Light color (above 127)
Luminance
0.4496
Relative luminance (0 = black, 1 = white)
Best Text Color
#000000
Contrast: 9.99:1
WCAG AA (Normal)
Pass
Requires 4.5:1 contrast ratio for normal text

Channel Breakdown

Red46 / 255 (0.18%)
Green204 / 255 (0.80%)
Blue113 / 255 (0.44%)

CMYK Values

ChannelValuePercentage
Cyan (C)0.77450.77%
Magenta (M)00.00%
Yellow (Y)0.44610.45%
Key/Black (K)0.20.20%

Contrast Ratios

BackgroundText ColorRatioAA NormalAA LargeAAA Normal
 White (#FFF)2.1:1FailFailFail
 Black (#000)9.99:1PassPassPass
Planning notes, formulas, and examples

About the RGB to Hex Converter

The RGB to Hex Converter takes decimal red, green, and blue values (0–255) and converts them to a hexadecimal color code (#RRGGBB) for use in CSS, HTML, and design tools. Enter your RGB values and review the hex code with a live color preview.

RGB values are the natural way to describe colors in programming — they map directly to the three light channels your screen uses. However, CSS shorthand and design tools often prefer hex notation for its brevity. Converting rgb(52, 152, 219) to #3498DB by hand requires converting each decimal value to a two-digit hex number.

This converter handles the math and validates that your values are in the valid range (0–255). It also shows the CSS rgb() format for copy-pasting into stylesheets.

When This Page Helps

Design tools often output RGB values, but CSS, brand guides, and style systems typically use hex codes. This converter bridges that gap with a live preview and matching hex value.

How to Use the Inputs

  1. Enter the red value (0–255).
  2. Enter the green value (0–255).
  3. Enter the blue value (0–255).
  4. View the hexadecimal color code below.
  5. Check the color preview swatch to verify visually.
  6. Copy the hex code for your project.
Formula used
hex = "#" + R.toString(16).padStart(2, "0") + G.toString(16).padStart(2, "0") + B.toString(16).padStart(2, "0") Each value is converted from decimal (0–255) to a two-digit hexadecimal string (00–FF).

Example Calculation

Result: #2ECC71

R=46 → 0x2E, G=204 → 0xCC, B=113 → 0x71. Combined: #2ECC71. This is the "Emerald" green from the Flat UI Colors palette. In CSS: rgb(46, 204, 113).

Tips & Best Practices

  • Remember that each hex pair represents one byte (0–255): 00 = 0, 7F = 127, FF = 255.
  • Values outside 0–255 are invalid — RGB channels are always unsigned 8-bit integers.
  • If you get a single-digit hex result (like "A"), pad it with a leading zero ("0A").
  • The hex output is case-insensitive in CSS: #2ecc71 and #2ECC71 are identical.
  • For transparency, add a 4th value (alpha): rgba(46, 204, 113, 0.8) or #2ECC71CC.

The RGB to Hex Conversion

Converting RGB to hex is a simple base conversion repeated three times. Each RGB channel (0–255 in decimal) becomes a two-character hexadecimal string (00–FF). The three pairs are concatenated with a # prefix to form the standard CSS hex color notation.

When to Use Hex vs. RGB

Hex is preferred for static, known colors in CSS and style guides due to brevity. RGB (and rgba for transparency) is preferred for dynamic colors computed in JavaScript, where channel manipulation is needed. Both produce identical results in browsers.

Color Accuracy Across Devices

The hex or RGB code defines a color in the sRGB color space. How that color appears on screen depends on the display's color gamut, brightness, and calibration. For critical color work (branding, print production), use color-managed workflows with calibrated monitors.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • Convert each decimal value (0–255) to hexadecimal (00–FF). For R=46: 46 ÷ 16 = 2 remainder 14. 2 = "2", 14 = "E", so 46 = "2E". Concatenate R+G+B hex pairs with a # prefix.