DEVELOPER PRECISION ENGINE

RGB to HEX Converter

Convert RGB color values to HEX format for CSS and design tools — RGB↔HEX and HSL↔HEX conversion math both verified correct against known reference colors. Output defaults to lowercase hex (#3b82f6); check the Uppercase box for #3B82F6-style output to match Figma-style conventions.

Results

HEX#3498db
HEX + A#3498dbff
RGBrgb(52, 152, 219)
RGBArgba(52, 152, 219, 1)
R
52
G
152
B
219
A
1

How to Use This Tool

1

Enter R, G, B values (0-255) for the color.

Enter R, G, B values (0-255) for the color.

2

Optionally add an alpha value (0-1) for transparency.

Optionally add an alpha value (0-1) for transparency.

Pro Tip

Single-digit hex conversions get zero-padded automatically — an RGB channel value of 5 converts to hex 05, not just 5, since every hex color code requires exactly two digits per channel. A converter that skips this padding produces a broken 5-digit code instead of a valid 6-digit one, which is a subtle bug worth checking for if you're ever writing this conversion logic yourself. Testing the edge cases of 0 and 255 explicitly is a good habit when validating any hand-rolled conversion function, since they map to the boundary hex values 00 and ff that are easy to get subtly wrong with an off-by-one error. It's also worth double-checking case sensitivity: hex color codes are conventionally written in either all-uppercase or all-lowercase for consistency across a codebase, and while browsers parse both identically, mixing cases inconsistently across a design system's token files tends to create noisy diffs in version control that make color changes harder to review at a glance. This tool defaults to lowercase but includes a real Uppercase toggle now, so match whichever convention your team already uses rather than hand-editing case after copying the value out. Establishing a single team-wide convention up front, and configuring a linter to enforce it automatically, removes this class of cosmetic inconsistency entirely rather than relying on manual review to catch it during code review.

About This Tool

When to Use

  • Converting an eyedropper-sampled RGB color from an image editor into a hex code for pasting into a CSS stylesheet
  • Translating RGB values computed by a programmatic color-manipulation script back into hex for a design token file
  • Converting a color picked via an RGB slider UI into the hex format expected by a content management system's color field

Key Details

An RGB-to-HEX converter translates red, green, blue channel values (0–255 each) into the 6-digit hexadecimal color code that CSS, design tools, and most color pickers use as the standard shorthand. De...

Worked example

Converting rgb(59, 130, 246) produces #3b82f6 by default — each channel value (59, 130, 246) converts from decimal to a two-digit hexadecimal pair, then the three pairs concatenate into the standard 6-digit hex code used across CSS, design tools, and version-controlled design token files alike. A near-black value like rgb(10, 10, 12) converts to #0a0a0c, illustrating how zero-padding keeps every channel exactly two digits even when the underlying decimal value is small. That same padding rule holds for every channel independently, so a color like rgb(255, 3, 200) still converts cleanly to #ff03c8 without any manual adjustment needed. Check the "Uppercase hex" box and the same three examples instead produce #3B82F6, #0A0A0C, and #FF03C8.

Interpreting your result

A correctly zero-padded 6-digit hex code confirms the conversion completed successfully. This tool defaults to lowercase output (#3b82f6) but includes a real "Uppercase hex" toggle for #3B82F6-style casing — check it once and every conversion (RGB and HSL alike) switches case consistently. Both cases are valid, equivalent CSS; the toggle exists purely for matching your own project's or design tool's convention.

RGB to HEX Converter FAQ

How do I convert RGB to HEX?

Each RGB channel value (0-255) is converted to a two-character hexadecimal value. For example, R=255 becomes ff, R=128 becomes 80, R=0 becomes 00. The three pairs are combined with a # prefix: rgb(255, 87, 51) = #ff5733. This tool defaults to lowercase output (#ff5733), matching most CSS style guides — check the "Uppercase hex" box if you need #FF5733-style output instead (a common convention in Figma and some design systems); both cases are valid, equivalent CSS.

What is the difference between rgb() and rgba()?

rgb() uses three values (red, green, blue). rgba() adds a fourth alpha parameter for opacity (0 = fully transparent, 1 = fully opaque). rgba(255, 0, 0, 0.5) is red at 50% opacity. Modern CSS also supports rgb() with a fourth value as well.

How do I convert HSL to hex?

HSL is first converted to RGB using the standard algorithm (hue angle → color wheel position, saturation and lightness determine color intensity and brightness). The resulting RGB values are then converted to hex. This tool supports both RGB-to-HEX and HSL-to-HEX conversion, confirmed via testing to produce consistent, round-trip-accurate results with the standard HSL formulas.

What is the HSL color model used for?

HSL (Hue, Saturation, Lightness) is more intuitive than RGB for humans. To make a color darker: lower the lightness. To desaturate: lower the saturation. To shift hue: change the hue angle. This makes creating color schemes (monochromatic, complementary) much easier than with RGB.

How do I add transparency to a hex color?

Convert your color to rgba() format or use 8-digit hex (#RRGGBBAA). For example, solid red rgb(255,0,0) with 50% opacity becomes rgba(255,0,0,0.5) or #FF000080. This tool generates both formats when you provide an alpha value.

Why do some RGB values not convert to clean hex?

They always convert cleanly — every RGB integer 0–255 maps to exactly two hex digits (00–FF). The potential issue is the reverse: when you type hex like #333, it expands to #333333 (rgb 51,51,51), not rgb(3,3,3). Always use 6-digit hex for unambiguous conversion.

Master Your Entire Toolkit

Access 500+ specialized calculators and tools designed for precision. No sign-up required, 100% free.

Built and reviewed by the Toolzip Team · Based on W3C CSS Color Specification