Supports 3-digit (#FFF), 6-digit (#7C5CFF), and 8-digit (#7C5CFF80) hex codes.
RGB rgb(124, 92, 255)
RGBA rgba(124, 92, 255, 1.0)
HSL hsl(252, 100%, 68%)
CSS VAR --color: #7C5CFF;
RGB Channel Fine-Tuning

1. What is a Hexadecimal (HEX) Color Code?

A hexadecimal color code is a six-digit alphanumeric string preceded by a hash symbol (#) used in HTML, CSS, SVG, and graphic design tools to define colors on digital displays. The format is structured as #RRGGBB, where the first two characters represent the Red channel, the middle two represent the Green channel, and the last two represent the Blue channel.

Hexadecimal uses base-16 arithmetic, which counts from 0 to 15 using the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and letters A, B, C, D, E, F (where A=10, B=11, C=12, D=13, E=14, F=15). Because each two-digit hex pair can express 256 unique values (16 × 16 = 256), a 6-digit hex code represents 256 × 256 × 256 = 16,777,216 distinct colors (24-bit TrueColor).

2. Understanding the RGB Color Model

The RGB color model is an additive color synthesis system based on human biological vision. Computer displays, smartphones, and television screens emit colored light directly toward your eyes. By combining varying intensities of Red, Green, and Blue light from 0 (completely off) to 255 (maximum intensity), displays reproduce any color within the standard sRGB gamut.

  • rgb(0, 0, 0): Zero light emitted across all three channels, producing pure black.
  • rgb(255, 255, 255): Full light emitted across all three channels, producing pure white.
  • rgb(255, 0, 0): Maximum red light with green and blue off, producing pure saturated red.
  • rgb(124, 92, 255): High blue with moderate red and green, producing ColorVerse Electric Violet.

3. Mathematical Conversion Formula: How to Convert HEX to RGB

Converting a hex code to decimal RGB is straightforward manual arithmetic. Take each two-digit hexadecimal pair and apply this formula:

Decimal Value = (First Character × 16) + (Second Character × 1)

Let's convert the color #7C5CFF step-by-step:

  1. Red Channel (7C): The first character is 7 (value 7), and the second is C (value 12).
    Calculation: (7 × 16) + (12 × 1) = 112 + 12 = 124.
  2. Green Channel (5C): The first character is 5 (value 5), and the second is C (value 12).
    Calculation: (5 × 16) + (12 × 1) = 80 + 12 = 92.
  3. Blue Channel (FF): Both characters are F (value 15).
    Calculation: (15 × 16) + (15 × 1) = 240 + 15 = 255.

Therefore, #7C5CFF maps to rgb(124, 92, 255). ColorVerse automates this calculation in real time as you type.

4. 3-Digit Shorthand and 8-Digit Alpha Hex Codes

In addition to standard 6-digit hex codes, modern CSS specifications support two important variations:

  • 3-Digit Shorthand (#RGB): When both characters in each pair are identical, you can write each pair as a single digit. For example, #FFFFFF becomes #FFF, #000000 becomes #000, and #FF55AA becomes #F5A. The browser automatically expands each character into duplicate pairs during stylesheet parsing.
  • 8-Digit Alpha Hex (#RRGGBBAA): CSS Color Module Level 4 allows specifying alpha transparency by appending two additional hex digits. For example, #7C5CFF80 represents Electric Violet at 50% opacity (hex 80 = 128 / 255 ≈ 0.50), equivalent to rgba(124, 92, 255, 0.5).

5. HEX to RGB Quick Reference Table

Color Swatch Color Name HEX Code RGB Notation HSL Equivalent
Pure Red#FF0000rgb(255, 0, 0)hsl(0, 100%, 50%)
Lime Green#00FF00rgb(0, 255, 0)hsl(120, 100%, 50%)
Pure Blue#0000FFrgb(0, 0, 255)hsl(240, 100%, 50%)
Electric Violet#7C5CFFrgb(124, 92, 255)hsl(252, 100%, 68%)
Neon Mint#5CF0C8rgb(92, 240, 200)hsl(164, 82%, 65%)
Hot Pink#FF5CAArgb(255, 92, 170)hsl(331, 100%, 68%)
Deep Charcoal#0A0A0Frgb(10, 10, 15)hsl(240, 20%, 5%)
Pure White#FFFFFFrgb(255, 255, 255)hsl(0, 0%, 100%)

6. How to Use HEX and RGB in Frontend Code

Here are practical code snippets showing how to convert and apply these values across modern stacks:

JavaScript Conversion Function

function hexToRgb(hex) { let c = hex.replace('#', ''); if (c.length === 3) c = c.split('').map(x => x + x).join(''); const num = parseInt(c, 16); return { r: (num >> 16) & 255, g: (num >> 8) & 255, b: num & 255 }; } // Usage: hexToRgb('#7C5CFF') -> { r: 124, g: 92, b: 255 }

Python Conversion Function

def hex_to_rgb(hex_code): hex_code = hex_code.lstrip('#') if len(hex_code) == 3: hex_code = ''.join([c*2 for c in hex_code]) return tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4)) # Usage: hex_to_rgb('#7C5CFF') -> (124, 92, 255)

7. Frequently Asked Questions (FAQ)

Why do developers use RGB instead of HEX?

Developers often prefer RGB when configuring CSS custom variables because separating channels allows dynamic alpha opacity adjustments using rgba(var(--brand-rgb), 0.2) without maintaining multiple separate hex codes.

Does HEX or RGB render faster in web browsers?

There is zero measurable performance difference during browser layout rendering. Modern browser engines parse both formats in microseconds. HEX saves a few bytes in file transfer size, while RGB offers greater programmatic flexibility.

What is the difference between HEX and HSL?

HEX represents color via physical hardware red, green, and blue light channels. HSL represents color through human-intuitive parameters: Hue (0-360° on color wheel), Saturation (0-100% color purity), and Lightness (0-100% brightness).

How do I test if my HEX color meets accessibility contrast requirements?

Use our free WCAG Contrast Checker. Enter your HEX color as the foreground and your background color to check compliance against Level AA (4.5:1) and Level AAA (7:1) standards.