🎨 Color Codes Explained: HEX, RGB, HSL & Color Theory for Designers

📅 June 25, 2026 · 14 min read · Design & Development

Every color you see on a website, app, or digital interface is described by a code — a precise mathematical representation of exactly which point in the color space that pixel should occupy. But the same color can be expressed in multiple formats: #0D5C46, rgb(13, 92, 70), hsl(161, 75%, 21%). Which format do you use? When? Why do they exist? And how does any of this connect to the colors you choose for your design in the first place?

This guide is the complete reference for color codes and color theory as they apply to digital design. We cover every format — HEX, RGB, RGBA, HSL, HSLA, and CMYK — with worked conversion examples, explain the color theory fundamentals that help you choose colors that work together, address web accessibility contrast requirements, provide a CSS usage guide, and walk through how to use our free Color Converter tool to convert between formats and explore colors visually.

How Computers Represent Color: The Foundations

The RGB Color Model: Light as Color

Digital screens — phones, laptops, monitors, televisions — produce color by emitting light. Every pixel contains three tiny light sources: Red, Green, and Blue. By varying the intensity of each from 0 (off) to 255 (maximum brightness), screens can produce approximately 16.7 million distinct colors. This is the additive color model: you start with black (no light) and add light to create color. Combining red and green light produces yellow. Combining all three at full intensity produces white light.

This is why RGB is the native language of screens: it maps directly to the physical hardware. Every color you specify in a web browser, design tool, or image editor is ultimately reduced to RGB values before being sent to the display. All other color formats — HEX, HSL, CMYK — are alternative ways of expressing or approximating the same underlying RGB values.

The Subtractive Model: How Print Is Different

Print works on the opposite principle. Paper starts white (reflecting all light). Inks absorb (subtract) portions of the spectrum. The CMYK model — Cyan, Magenta, Yellow, and Key (Black) — works by layering transparent ink pigments that each absorb specific light wavelengths. Mixing all three colors (CMY) theoretically produces black, but in practice produces a muddy dark brown; a separate black (K) ink is required for clean, deep blacks.

This fundamental difference between additive (screen) and subtractive (print) color means that RGB colors cannot always be reproduced exactly in CMYK print. Certain highly saturated blues, greens, and oranges visible on screen fall outside the CMYK gamut — the range of colors reproducible with those inks on paper. This is why designs created for screen often look different when printed, and why professional print workflows require converting from RGB to CMYK before sending to press.

HEX Color Codes: The Web Standard

What Is a HEX Code?

A HEX color code is a 6-digit (or 3-digit shorthand) representation of an RGB color in base-16 (hexadecimal) notation, prefixed with #. The six digits split into three pairs: the first pair is Red, the second is Green, the third is Blue. Each pair represents a value from 00 (0 in decimal) to FF (255 in decimal).

For ToolWeb's brand green: #0D5C46:

3-Digit HEX Shorthand

When each pair in a HEX code consists of two identical digits, it can be shortened to a single digit. #FFCC00 can be written as #FC0; #112233 as #123. The browser expands each digit by doubling it — #FC0#FFCC00. This shorthand only works when both digits in each pair are the same; it cannot shorten arbitrary codes like #0D5C46.

8-Digit HEX with Alpha (Transparency)

Modern CSS supports an 8-digit HEX format that adds an alpha channel: #RRGGBBAA. The last two digits represent opacity from 00 (fully transparent) to FF (fully opaque). #0D5C4680 is ToolWeb green at approximately 50% opacity. This is mathematically equivalent to rgba(13, 92, 70, 0.5).

When to Use HEX

RGB and RGBA: The Intuitive Format

RGB Syntax

The CSS rgb() function takes three parameters — red, green, blue — each as an integer from 0 to 255. rgb(13, 92, 70) is ToolWeb green. In CSS Level 4, commas are optional: rgb(13 92 70) is equivalent. Both syntaxes are supported in all modern browsers.

RGBA: Adding Transparency

The rgba() function adds a fourth parameter: alpha, from 0 (fully transparent) to 1 (fully opaque). rgba(13, 92, 70, 0.5) is ToolWeb green at 50% opacity. This is the most readable format for transparent colors because the opacity value (0.5) is immediately interpretable, unlike the hex equivalent (#0D5C4680) which requires mental hex-to-decimal conversion.

Practical RGB Color Reference

Color NameHEXRGBNotes
Pure Red#FF0000rgb(255, 0, 0)Maximum red channel
Pure Green#00FF00rgb(0, 255, 0)Maximum green channel
Pure Blue#0000FFrgb(0, 0, 255)Maximum blue channel
White#FFFFFFrgb(255, 255, 255)All channels maximum
Black#000000rgb(0, 0, 0)All channels zero
Medium Gray#808080rgb(128, 128, 128)Equal channels at half
ToolWeb Green#0D5C46rgb(13, 92, 70)Brand primary
Emerald#4ADE80rgb(74, 222, 128)Tailwind emerald-400

HSL and HSLA: The Designer's Color Model

Why HSL Exists

RGB is efficient for machines but unintuitive for humans. If you have rgb(13, 92, 70) and want a lighter version of the same color, how do you modify it? You would need to understand how each of the three channels contributes to perceived lightness — a non-obvious calculation. HSL solves this by separating color into three properties that map to how humans actually think about color:

The Three HSL Parameters

ToolWeb green (#0D5C46) in HSL: hsl(161, 75%, 21%). Hue 161° is a blue-green (teal/emerald range). Saturation 75% is highly vivid. Lightness 21% is quite dark — a deep forest green.

The Power of HSL in Design Systems

HSL's true advantage is in design systems and component libraries. Consider these operations that are trivial in HSL but require calculation in RGB:

/* Design system using HSL — easy to maintain */
:root {
  --brand-hue: 161;
  --brand-sat: 75%;

  --color-primary:      hsl(var(--brand-hue), var(--brand-sat), 21%);
  --color-primary-light:hsl(var(--brand-hue), var(--brand-sat), 40%);
  --color-primary-pale: hsl(var(--brand-hue), 30%, 90%);
  --color-primary-dark: hsl(var(--brand-hue), var(--brand-sat), 12%);
}

CMYK: The Print Standard

CMYK Syntax and Values

CMYK expresses color as four percentage values: Cyan, Magenta, Yellow, and Key (Black), each from 0% to 100%. cmyk(86%, 0%, 24%, 64%) approximates ToolWeb green in print. CMYK is not natively supported in CSS — it is used exclusively in print workflows through design software (Adobe Illustrator, InDesign, Photoshop) and sent to printers as ICC-profiled CMYK PDFs.

The RGB-to-CMYK Conversion Problem

Converting between RGB and CMYK is not a simple mathematical formula — it involves color profiles (ICC profiles) that account for the specific characteristics of the inks and paper being used. A CMYK value calculated purely mathematically (without a profile) gives an approximation, not a press-accurate result. For professional print work, always let a profiled conversion in Adobe software or your print provider's preflight tool handle the conversion — never rely on online calculators for print-critical color accuracy.

Color ModelFormatUse CaseTransparency Support
HEX#RRGGBB or #RRGGBBAAWeb CSS (static colors)✅ (8-digit)
RGBrgb(R, G, B)Web CSS (programmatic)
RGBArgba(R, G, B, A)Web CSS (with transparency)
HSLhsl(H, S%, L%)Design systems, theming
HSLAhsla(H, S%, L%, A)Design systems + transparency
CMYKcmyk(C%, M%, Y%, K%)Print only; not in CSS

Color Theory Fundamentals for Digital Designers

The Color Wheel and Harmony Schemes

Color harmony refers to combinations of colors that are aesthetically pleasing because of their geometric relationship on the color wheel. These are not arbitrary preferences — they are patterns identified through centuries of art and design practice. The major harmony schemes:

MonochromaticOne hue, varied lightness/saturation
ComplementaryOpposite hues — high contrast
TriadicThree evenly spaced hues
Harmony TypeDefinitionEffectBest For
MonochromaticOne hue, multiple lightness/saturation valuesCohesive, sophisticated, restrainedProfessional, minimal brands
Analogous2–4 adjacent hues on the wheel (within 60°)Harmonious, calm, naturalNature brands, wellness, lifestyle
ComplementaryTwo opposite hues (180° apart)High contrast, energetic, attention-grabbingCTAs, sports, retail promotions
Split-complementaryA hue + two colors adjacent to its complementHigh contrast without direct clashBalanced vibrance
TriadicThree hues equally spaced (120° apart)Vibrant, playful, balancedChildren's brands, creative industries
Tetradic / SquareFour hues equally spaced (90° apart)Rich variety; complex to balanceAdvanced design systems

Color Psychology in Web Design

Color associations vary significantly across cultures, but some patterns are broadly consistent in Western digital product design:

ColorCommon AssociationsCommon Use Cases
BlueTrust, stability, calm, professionalismBanks, social media, healthcare, tech (Facebook, PayPal, LinkedIn)
GreenGrowth, nature, health, success, go/yesFinance apps (Robinhood), health, sustainability, CTAs
RedUrgency, danger, passion, energySale labels, error states, food delivery, sports
OrangeEnthusiasm, creativity, affordability, warmthE-commerce discounts, food, creative tools
YellowOptimism, caution, attention, warmthWarnings, highlights, children's brands
PurpleLuxury, creativity, spirituality, mysteryPremium brands, beauty, gaming
BlackSophistication, power, luxury, eleganceHigh fashion, premium tech, editorial
WhiteCleanliness, simplicity, space, healthMedical, minimal design, Apple products

Color Accessibility: WCAG Contrast Ratios

Approximately 8% of men and 0.5% of women have some form of color vision deficiency (commonly called color blindness). Web accessibility standards require that text be readable regardless of color perception. The Web Content Accessibility Guidelines (WCAG) define minimum contrast ratios between text and its background:

WCAG StandardNormal TextLarge Text (18pt+ or 14pt bold)UI Components
AA (minimum)4.5:13:13:1
AAA (enhanced)7:14.5:1

A white text (#FFFFFF) on ToolWeb green (#0D5C46) has a contrast ratio of approximately 7.2:1, which passes both AA and AAA for normal text. Black on white achieves the maximum 21:1 ratio. To check any color pair, tools like WebAIM's Contrast Checker or the browser DevTools accessibility panel calculate the ratio automatically.

⚠️ Common accessibility mistake: Light gray text on a white background (e.g., #AAAAAA on #FFFFFF) has a contrast ratio of approximately 2.3:1 — failing WCAG AA for normal text. Many "clean" minimal designs fail this check. Always verify your text/background color pairs before launch.

CSS Color Usage Guide (2026)

All CSS Color Formats at a Glance

/* All represent ToolWeb green (#0D5C46 = rgb(13,92,70) = hsl(161,75%,21%)) */

/* HEX */
color: #0D5C46;

/* RGB */
color: rgb(13, 92, 70);

/* RGB (CSS Level 4 — no commas) */
color: rgb(13 92 70);

/* RGBA — 50% transparent */
color: rgba(13, 92, 70, 0.5);

/* HSL */
color: hsl(161, 75%, 21%);

/* HSLA — 50% transparent */
color: hsla(161, 75%, 21%, 0.5);

/* 8-digit HEX — 50% transparent */
color: #0D5C4680;

/* CSS custom properties (recommended for design systems) */
:root { --brand-green: #0D5C46; }
.element { color: var(--brand-green); }

/* Modern: oklch (perceptually uniform, 2024+) */
color: oklch(38% 0.09 161);

Choosing the Right Format for Your Project

How to Use ToolWeb's Free Color Converter

What the Tool Converts

ToolWeb's Color Converter converts between HEX, RGB, and HSL — the three formats most commonly needed for web and digital design work. It also includes a visual color picker so you can select colors interactively and instantly see all three format equivalents.

Step 1 — Open the Color Converter

Navigate to toolweb.info/color-converter.html. No account, no download. The tool loads with ToolWeb's brand green as the default color.

Step 2 — Pick a Color Visually

Click the color picker (the tall colored rectangle at the top of the tool) to open your browser's native color selection interface. Choose any color you want to work with — drag across the gradient to find the hue, saturation, and lightness you need.

Step 3 — Read All Three Format Outputs

As you select a color, the HEX, RGB, and HSL values update instantly in the three display panels. Each has a Copy button — click it to copy that format directly to your clipboard for pasting into your CSS, design tool, or documentation.

Step 4 — Convert a Specific HEX Code

If you have a specific HEX code you want to convert (from a brand guideline or a design file), you can use the color picker to enter it manually. In most browsers, the native color picker has a hex input field — type or paste your code there and the tool updates all three outputs immediately.

Step 5 — Explore Color Variations

Use the lightness slider in the color picker to create lighter or darker versions of your color, then copy each variation's HEX code. This is a fast way to build a monochromatic palette from a single brand color.

🎨 Convert Any Color Instantly

ToolWeb's free Color Converter converts between HEX, RGB, and HSL with a live visual picker. Perfect for designers, developers, and anyone working with digital color. No sign-up required.

🎨 Open Color Converter

FAQ — Color Codes Answered

What is the difference between HEX and RGB color codes?

HEX and RGB represent the same color information in different formats. RGB uses three decimal numbers (0–255) for Red, Green, Blue: rgb(255, 99, 71). HEX uses base-16 pairs prefixed with #: #FF6347. FF = 255, 63 = 99, 47 = 71. They are mathematically interchangeable with exact conversion — HEX is more compact; RGB is more intuitive for adjusting individual channels.

What does HSL stand for in color codes?

Hue, Saturation, Lightness. Hue = position on the color wheel (0–360°: 0=red, 120=green, 240=blue). Saturation = intensity (0% gray to 100% pure color). Lightness = brightness (0% black, 50% pure color, 100% white). HSL is preferred for design systems because each parameter maps directly to a human-understandable color property.

What is the difference between RGB and CMYK?

RGB is an additive light model for screens — mixing red, green, and blue light produces all colors, with full intensity producing white. CMYK is a subtractive ink model for print — layering cyan, magenta, yellow, and black inks absorbs light wavelengths to produce color. The two have different gamuts (color ranges), so RGB colors cannot always be exactly reproduced in CMYK print.

How do I convert HEX to RGB?

Split the 6-digit hex into three pairs and convert each from base-16 to decimal. For #1A8466: 1A = (1×16)+10 = 26; 84 = (8×16)+4 = 132; 66 = (6×16)+6 = 102. Result: rgb(26, 132, 102). ToolWeb's Color Converter automates this for any color instantly.

What is color contrast ratio and why does it matter for accessibility?

Contrast ratio measures luminance difference between text and background (1:1 = no contrast; 21:1 = maximum). WCAG 2.1 AA requires 4.5:1 for normal text, 3:1 for large text. AAA requires 7:1. These standards ensure readability for users with low vision or color deficiency. Approximately 8% of men have some form of color vision deficiency.

What are complementary colors?

Colors directly opposite on the color wheel (180° apart). Common pairs: Red/Green, Blue/Orange, Yellow/Violet. They create maximum visual contrast and make each other appear more intense. In web design, complementary schemes work well for calls-to-action. Pair a saturated version of one with a muted version of its complement for a more sophisticated result than full-saturation clash.

What color format should I use in CSS?

HEX for static colors (shortest, most common). RGBA when you need transparency. HSL with CSS custom properties for design systems (most maintainable — adjust one value to change all derived colors). CMYK is not supported in CSS and should only be used in print design software.

How do I pick colors that work well together?

Use established color harmony schemes from the color wheel: Complementary (two opposite colors — high contrast), Analogous (adjacent colors — harmonious), Triadic (three evenly spaced colors — balanced vibrance), or Monochromatic (one hue, varied lightness — cohesive). Start with your primary hue, then derive supporting colors using a harmony scheme. ToolWeb's Color Converter helps you explore these visually.

What is the #RRGGBBAA format?

An 8-digit HEX that adds two digits for the alpha (opacity) channel. #0D5C4680 = ToolWeb green at ~50% opacity (80 hex = 128 decimal = 128/255 ≈ 50%). Supported in all modern browsers but less readable than rgba() notation for transparency, because the hex math is less intuitive than a 0–1 decimal.

Color CodesHEXRGBHSLWeb DesignCSSAccessibility