🎨

Color Converter (HEX, RGB, HSL)

Convert between color formats

HEX in
#3B82F6
RGB out
rgb(59, 130, 246)
RGB
HSL

All formats

Lightness variations

Understanding Color Formats

Colors on screens are created by combining light. Different color formats represent the same colors using different mathematical models. Understanding when to use each format helps you work more efficiently in design and development.

Color Format Reference

HEX (Hexadecimal)

The most common format for web colors. Each pair of characters represents Red, Green, and Blue values in base-16 (0-9, A-F).

``css color: #FF5733; /* Full format: RRGGBB */ color: #F53; /* Shorthand: RGB (expands to #FF5533) */ color: #FF573380; /* With alpha: RRGGBBAA (50% opacity) */ `

Structure: #RRGGBB where each component ranges from 00 (0) to FF (255).

RGB (Red, Green, Blue)

Represents colors as three decimal values from 0-255. More intuitive for programmatic manipulation.

`css color: rgb(255, 87, 51); /* Standard RGB */ color: rgba(255, 87, 51, 0.5); /* With alpha (0-1) */ color: rgb(255 87 51 / 50%); /* Modern syntax */ `

HSL (Hue, Saturation, Lightness)

The most intuitive format for creating color variations and themes.

`css color: hsl(11, 100%, 60%); /* H: 0-360°, S: 0-100%, L: 0-100% */ color: hsla(11, 100%, 60%, 0.5); /* With alpha */ color: hsl(11 100% 60% / 50%); /* Modern syntax */ `

Understanding HSL values:

  • Hue (H): Color wheel position (0°=red, 120°=green, 240°=blue)
  • Saturation (S): Color intensity (0%=gray, 100%=vivid)
  • Lightness (L): Brightness (0%=black, 50%=pure color, 100%=white)

When to Use Each Format

FormatBest ForAdvantages
HEXDesign specs, quick colorsCompact, universal support
RGBProgrammatic manipulationEasy math operations
HSLColor schemes, themingIntuitive adjustments
CMYKPrint designMatches printing process
HSV/HSBDesign softwareNatural color selection

Color Conversion Formulas

HEX to RGB

`javascript function hexToRgb(hex) { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; } // hexToRgb("#FF5733") → { r: 255, g: 87, b: 51 } `

RGB to HSL

`javascript function rgbToHsl(r, g, b) { r /= 255; g /= 255; b /= 255; const max = Math.max(r, g, b), min = Math.min(r, g, b); let h, s, l = (max + min) / 2;

if (max === min) { h = s = 0; } else { const d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch (max) { case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break; case g: h = ((b - r) / d + 2) / 6; break; case b: h = ((r - g) / d + 4) / 6; break; } } return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) }; } `

HSL Color Manipulation

HSL makes color adjustments intuitive. Starting with hsl(200, 80%, 50%):

AdjustmentChangeResult
LighterL: 50% → 70%hsl(200, 80%, 70%)
DarkerL: 50% → 30%hsl(200, 80%, 30%)
Muted/DesaturatedS: 80% → 40%hsl(200, 40%, 50%)
Vivid/SaturatedS: 80% → 100%hsl(200, 100%, 50%)
ComplementaryH: +180°hsl(20, 80%, 50%)
AnalogousH: ±30°hsl(170, 80%, 50%) or hsl(230, 80%, 50%)

CSS Custom Properties for Theming

Using HSL with CSS variables enables powerful theming:

`css :root { /* Define color as components */ --primary-h: 200; --primary-s: 80%; --primary-l: 50%;

/* Compose variations */ --primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l)); --primary-light: hsl(var(--primary-h), var(--primary-s), 70%); --primary-dark: hsl(var(--primary-h), var(--primary-s), 30%); --primary-muted: hsl(var(--primary-h), 40%, var(--primary-l)); }

/* Theme switching becomes trivial */ [data-theme="dark"] { --primary-l: 60%; } ``

Color Accessibility

When choosing colors, ensure sufficient contrast for readability:

WCAG LevelContrast RatioUse Case
AA (minimum)4.5:1Normal text
AA Large3:1Large text (18pt+)
AAA (enhanced)7:1Maximum accessibility
Use a contrast checker to verify your color combinations meet accessibility standards.

Frequently Asked Questions

What is the difference between RGB and HEX?

They represent the same colors differently. RGB uses decimal values 0-255 for red, green, and blue. HEX uses the same values in hexadecimal (00-FF). #FF0000 and rgb(255, 0, 0) are both pure red.

When should I use HSL?

HSL (Hue, Saturation, Lightness) is intuitive for creating color variations. To make a color lighter, increase L. To make it more muted, decrease S. It's great for generating consistent color palettes programmatically.

What is color opacity/alpha?

Alpha (A in RGBA/HSLA) controls transparency from 0 (invisible) to 1 (opaque). Use rgba(255, 0, 0, 0.5) for 50% transparent red. Modern CSS also supports #RRGGBBAA format.

Related Tools

Explore other tools you might find useful:

Browse by category

All 99 versions, grouped by what they measure.

Most used

Try our targeted calculators for specific use cases: