DocumentsImagesMediaPDF Tools

RGB to HEX

Convert RGB and RGBA values to HEX code instantly, in your browser.

Processed in your browser

From RGB values to the correct HEX code

Supports RGBA

Also converts colors with transparency. The alpha channel is included in the 8-character HEX result.

Private

No servers, no logs. Conversion happens entirely in your browser.

Automatic clamping

Out-of-range values are automatically adjusted to the valid value without errors.

Instant

Real-time result as you adjust the RGB values.

Three steps, no hassle

1

Enter the RGB values

Type the values for the red (R), green (G), and blue (B) channels in the 0-255 range. Optionally add the alpha (A) channel between 0 and 1 to get a HEX code with transparency (#RRGGBBAA).

2

Automatic conversion

The converter instantly calculates the corresponding HEX code. Values outside the 0-255 range are automatically clamped to the nearest valid value. Decimal values are rounded to the nearest integer.

3

Copy the HEX code

Get the result in #RRGGBB or #RRGGBBAA format, ready to use in CSS, HTML, SVG, or any design tool that accepts HEX codes.

Got questions?

RGB (Red, Green, Blue) is an additive color model based on light emission. Mixing all three primary colors at maximum (R=255, G=255, B=255) produces white; with all at zero (0,0,0) you get black. The RGB model reflects how pixels in modern screens and monitors work: each pixel contains three subpixels (red, green, and blue) that illuminate at different intensities to create any visible color. It is also the model used by the human eye: the retina has three types of cones sensitive to wavelengths close to red, green, and blue.

The 0-255 range corresponds to 8 bits per color channel. One byte (8 bits) can represent 2⁸ = 256 distinct values (0 to 255). With 8 bits per channel and 3 channels (R, G, B), each color occupies 24 bits (3 bytes), allowing 256³ = 16,777,216 distinct colors. This 24-bit true color standard was universally adopted in the 1990s when VGA and SVGA monitors began supporting it. Modern HDR screens use 10 or 12 bits per channel (1,024 or 4,096 values), but the web sRGB space remains defined in 8 bits for compatibility.

Valid RGB values are in the 0-255 range. If you enter a value like R=300, most CSS implementations clamp it to the nearest valid maximum: 255. This clamping behavior is defined in the CSS Color Level 4 specification. In practice it occurs when making mathematical calculations with colors (for example, mixing two colors by summing their values), or when importing colors from higher bit-depth spaces (16-bit or HDR). CSS's clamp() function and mathematical operators in oklch are designed to handle these cases in a controlled way.

RGBA adds a fourth alpha (A) channel to the RGB model to control the opacity/transparency of the color. The alpha value ranges from 0 (fully transparent) to 1 (fully opaque), though in CSS it can also be expressed as a percentage (0% to 100%). rgba(255, 87, 51, 0.5) is the color rgb(255,87,51) at 50% opacity. The alpha channel affects how the color is composited over elements behind it, following the 'source-over' compositing mode of the SVG/HTML compositing specification (W3C Compositing and Blending Level 1).

Screens use RGB because they emit light, and mixing red, green, and blue light can recreate any color in the visible spectrum for the human eye (within the device's gamut). This corresponds to the Young-Helmholtz trichromatic theory (Thomas Young, 1802; Hermann von Helmholtz, 1850), which demonstrated that the human eye has three types of photoreceptors (S, M, L cones) sensitive to approximate wavelengths of 420nm (blue), 530nm (green), and 560nm (red). The first color CRT monitors of the 1970s-80s implemented this architecture directly, and modern LCDs, OLEDs, and microLEDs have inherited it.

RGB: history from Young-Helmholtz to the sRGB standard

The trichromatic theory of color was proposed by Thomas Young in 1802 and extended by Hermann von Helmholtz in 1850, establishing that the human eye perceives colors through three types of receptors sensitive to long (red), medium (green), and short (blue) wavelengths. James Clerk Maxwell experimentally demonstrated additive color synthesis in 1861 by creating the first color photograph in history: he superimposed three black-and-white photographs taken with red, green, and blue filters, projecting them simultaneously with correspondingly colored lanterns. The resulting image of a Scottish tartan is considered the first color photograph (though reproduction was imperfect due to the limitations of the collodion of the era).

The additive RGB color model applied to screens originated in cathode ray tubes (CRT) of the 1950s-60s, which used three-color phosphors to emit red, green, and blue light when excited by an electron beam. The first commercial color CRT monitor was the IBM 8503 (1984). Gamma correction, which compensates for the non-linear relationship between electrical voltage and perceived brightness of CRT monitors, became a fundamental component of the sRGB standard: the sRGB space defines a color transfer curve (TRC) that applies an approximately 2.2 gamma correction, designed so that linear RGB values (as calculated in 3D shaders) are correctly converted to perceptually uniform values for the display.

Gamma encoding has critical implications for color mixing calculations. Mixing two sRGB colors by directly summing and averaging their RGB values produces incorrect results (colors too dark at the midpoint) because sRGB values are non-linear. Perceptually correct mixing requires first converting to linear space (gamma 1.0), averaging, and converting back. This problem affects CSS gradients, font antialiasing, layer compositing in image editors, and any color interpolation. CSS Color Level 4 addresses this with linear (srgb-linear) and perceptually uniform (oklch, oklab) color spaces that allow explicitly specifying the interpolation space.