
If you work in graphic design, UI, branding, or even interior mood boards, you’ve seen strings like #1E90FF or #F2F2F2. That format—commonly called HEX color—is one of the fastest ways to specify an exact color for digital work. Yet many creative workflows still treat hex codes like magic: copy, paste, hope it looks right.
This guide demystifies hex color codes so you can read them confidently, convert them correctly, and use them consistently across real projects—from web pages and apps to presentations and palette boards built from photos.
What is a HEX color code?
A HEX color code is a compact way to represent a color using hexadecimal numbers (base-16). In most design tools and web contexts, a hex code is written as:
#RRGGBB
Where:
- RR = red channel intensity
- GG = green channel intensity
- BB = blue channel intensity
Each pair uses two hex digits from 00 to FF (0–255 in decimal). For example:
- #000000 is black (0 red, 0 green, 0 blue)
- #FFFFFF is white (255 red, 255 green, 255 blue)
- #FF0000 is pure red
How to read HEX color values (without guessing)
Once you know that 00 means “none” and FF means “max,” you can interpret a hex color at a glance:
- #0A0A0A is a very dark gray (low values across all channels).
- #F5E6A1 is a warm, light yellow (high red, high green, moderate blue).
- #1B3C8F is a deep blue (blue channel is high compared to red/green).
Quick mental map of common hex pairs
You don’t need to memorize everything, but these landmarks help:
- 00 = 0
- 33 ≈ 51 (about 20%)
- 66 ≈ 102 (about 40%)
- 80 = 128 (50%)
- 99 ≈ 153 (about 60%)
- CC ≈ 204 (about 80%)
- FF = 255 (100%)
HEX color vs RGB, HSL, and HSB: when each matters
Hex is essentially a different notation for RGB, which is why it’s common in web and UI. But you’ll often switch between formats depending on the task:
| Format | Best for | Why it’s useful |
|---|---|---|
| HEX (#RRGGBB) | Web, UI specs, handoffs | Compact, copy/paste friendly, widely supported |
| RGB (0–255) | Digital color accuracy | Matches how screens emit color |
| HSL (Hue/Saturation/Lightness) | Palette tuning | Easier to “nudge” lightness or saturation predictably |
| HSB/HSV (Hue/Saturation/Brightness) | Picker-style adjustments | Common in design apps; intuitive for brightening/dimming |
Practical takeaway: use hex color for final specs and consistency, but use HSL/HSB while refining a palette.
Short HEX codes and alpha: the variations that trip people up
1) 3-digit shorthand
Some hex colors are shortened from #RRGGBB to #RGB when each channel repeats the same digit:
#FFFexpands to#FFFFFF#09Cexpands to#0099CC
2) HEX with alpha (transparency)
Modern CSS also supports 8-digit hex:
#RRGGBBAA
Where AA is the alpha channel (opacity). Example:
#00000080= black at ~50% opacity
Note: Not every tool exports alpha the same way. Some use
#AARRGGBB(common in certain platforms). Always confirm the expected order before you paste.
How to convert HEX color to RGB (and back)
Conversion is straightforward: convert each two-character pair from hex to decimal.
Example: #1E90FF
- 1E (hex) = 30 (decimal) → Red = 30
- 90 (hex) = 144 (decimal) → Green = 144
- FF (hex) = 255 (decimal) → Blue = 255
So #1E90FF = rgb(30, 144, 255).
JavaScript snippet: HEX → RGB
function hexToRgb(hex) {
const clean = hex.replace('#', '').trim();
const full = clean.length === 3
? clean.split('').map(ch => ch + ch).join('')
: clean;
const r = parseInt(full.slice(0, 2), 16);
const g = parseInt(full.slice(2, 4), 16);
const b = parseInt(full.slice(4, 6), 16);
return { r, g, b };
}
console.log(hexToRgb('#1E90FF')); // { r: 30, g: 144, b: 255 }
Using HEX color in a real palette workflow (especially from photos)
Many palettes start with inspiration: a room, a fabric swatch, a product shot, a landscape photo. The challenge is translating that inspiration into reusable, reliable hex color values that behave well across screens and contexts.
Step-by-step: from image to usable HEX colors
- Choose the right source image. Prefer evenly lit photos and avoid strong filters. If possible, use an original photo rather than a compressed screenshot.
- Identify “role” colors before picking values. Aim for: primary, secondary, accent, background, surface, and text colors.
- Sample multiple points per material. A “white wall” has shadows and highlights; sample 3–5 spots and average mentally (or pick the midtone).
- Normalize in HSL. After extracting a hex color, adjust lightness and saturation to create consistent steps (e.g., 10–15% lightness increments for UI surfaces).
- Test contrast early. A palette that looks beautiful as swatches can fail as text and buttons.
Common photo-extraction pitfalls (and how to avoid them)
- Auto white balance shifts: Two photos of the same object can yield different hex colors. If consistency matters, extract from the same lighting condition or correct white balance first.
- Specular highlights: Shiny surfaces produce near-white pixels that are not the “true” color. Sample away from glare.
- Compression artifacts: JPEG blocks can introduce color noise. Zoom in and sample several nearby pixels.
- Out-of-gamut expectations: Some vivid real-world colors (especially pigments) won’t match perfectly on screen. Treat extracted hex colors as a digital approximation.
Contrast and accessibility: make hex colors usable, not just pretty
A key difference between a palette that’s “nice” and one that’s usable is contrast. If you’re designing anything with text, you should evaluate contrast ratios for common pairings (text on background, buttons, links, etc.).
Quick contrast check approach
At minimum, test these combinations:
- Primary text on background
- Secondary text on background
- Button text on button background
- Link color on background (plus hover/visited states)
JavaScript snippet: relative luminance (building block for contrast)
function srgbToLinear(c) {
c /= 255;
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
}
function relativeLuminance({ r, g, b }) {
const R = srgbToLinear(r);
const G = srgbToLinear(g);
const B = srgbToLinear(b);
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
}
Once you can compute luminance for two hex colors, you can compute contrast ratio. Even if you don’t write code, the key habit is the same: verify readability for your chosen hex color pairs.
Building a “system” from hex colors: naming, roles, and variants
Random hex codes pasted into a file don’t scale. A small amount of structure makes your palette reusable across tools and teammates.
1) Name colors by role, not by hue
Instead of:
blue1,blue2,blue3
Prefer:
color-primary,color-primary-hover,color-primary-pressedtext-default,text-muted,surface-1,surface-2
2) Create consistent light/dark steps
If you need multiple shades, generate them intentionally (often in HSL): keep hue stable, adjust lightness in predictable increments, and watch saturation so your neutrals don’t unintentionally tint.
3) Document your palette in a simple table
| Role | HEX | RGB | Usage example |
|---|---|---|---|
| Background | #F7F7F8 |
rgb(247, 247, 248) |
App/page background |
| Text (default) | #1A1D21 |
rgb(26, 29, 33) |
Body text |
| Primary | #2D6CDF |
rgb(45, 108, 223) |
Buttons, links |
| Accent | #F4B942 |
rgb(244, 185, 66) |
Highlights, badges |
HEX color in CSS and design handoff: copy/paste patterns that reduce mistakes
Hex colors show up in many places—CSS, design tokens, documentation, and specs. A few conventions prevent the most common errors:
- Always include the leading “#” when the target format expects it (CSS does).
- Stick to one casing (upper or lower). CSS doesn’t care, but humans do when comparing values.
- Prefer 6-digit codes in documentation to avoid confusion with shorthand.
- Record the source context when extracted from photos (lighting, material, image link), especially for interior design references.
Example: CSS variables for a hex color palette
:root {
--color-bg: #F7F7F8;
--color-text: #1A1D21;
--color-primary: #2D6CDF;
--color-accent: #F4B942;
}
body {
background: var(--color-bg);
color: var(--color-text);
}
a {
color: var(--color-primary);
}
A practical checklist for choosing “good” hex colors
- Does it have a role? (primary, surface, text, accent)
- Is it consistent across screens? Check at least two displays if accuracy matters.
- Is contrast acceptable? Test text/background and interactive states.
- Do you have variants? Hover/pressed/disabled states for UI; lighter/darker steps for layouts.
- Is it documented? Name, hex value, and intended usage.
Closing thought: treat HEX as the “final answer,” not the whole process
A hex color code is best viewed as the precision output of your color decisions. The best results come from combining accurate sampling (especially from photos), sensible conversion and normalization (often in HSL), and practical testing for readability and consistency.
If you like building palettes from images on iPhone or iPad, an app like Color Viewfinder can help you extract and export hex values quickly—just pair the speed with the checks above to keep your palettes project-ready.
