Colour is one of the most important design decisions on a webpage, and it is also one of the most technically fragmented. Designers work in HEX codes. Developers writing CSS for transparency need RGBA. Design systems increasingly use HSL for programmatic colour generation. Cutting-edge CSS now supports OKLCH as a perceptually uniform colour space. And every tool in the chain - Figma, VS Code, browser DevTools, design tokens - uses a different default format. The ability to convert between colour formats quickly is not a niche skill - it is a core part of modern web workflow. This guide explains how each format works, when to use which, and how to convert between them accurately.
How Colour Codes Work: The Four Main Formats
All four common colour formats ultimately describe the same colour from different mathematical perspectives. Understanding what each format measures makes conversion intuitive rather than mechanical.
- HEX (Hexadecimal) - six hexadecimal digits representing three bytes of red, green, and blue values. Each pair of digits (00 to FF) represents one colour channel, where 00 is zero intensity and FF is maximum intensity. #FF6A1A means red=FF (255), green=6A (106), blue=1A (26). Used almost universally in CSS, HTML, and design tool colour pickers. Three-digit shorthand (#FFF for #FFFFFF) is supported for colours where each pair is a repeated digit.
- RGB (Red, Green, Blue) - three integer values, each from 0 to 255, representing the intensity of red, green, and blue light. `rgb(255, 106, 26)` is identical to #FF6A1A. RGBA adds a fourth parameter for alpha (opacity), from 0.0 (fully transparent) to 1.0 (fully opaque): `rgba(255, 106, 26, 0.5)` is the same orange at 50% opacity. Modern CSS allows the four-value syntax without the 'a': `rgb(255 106 26 / 0.5)`.
- HSL (Hue, Saturation, Lightness) - describes colour by how humans perceive it rather than how a screen renders it. Hue is a degree on the colour wheel (0 to 360, where 0 and 360 are both red, 120 is green, 240 is blue). Saturation is the intensity from 0% (grey) to 100% (fully saturated). Lightness is the brightness from 0% (black) to 100% (white). `hsl(20, 100%, 55%)` represents a bright orange. HSL is invaluable for programmatic colour manipulation - generating colour scales by incrementing lightness in a loop.
- HSB/HSV (Hue, Saturation, Brightness/Value) - similar to HSL but with a different lightness model. HSB is used in Photoshop and some design tools. It is distinct from HSL even though both describe hue and saturation - the same HSB and HSL values produce different colours. When working across tools, confirm which model is in use.
Converting HEX to RGB Manually: The Mathematics
Understanding the maths behind HEX-to-RGB conversion demystifies colour codes permanently. HEX is base-16 notation. Each digit can be 0-9 or A-F (where A=10, B=11, C=12, D=13, E=14, F=15). To convert a two-digit HEX pair to decimal: multiply the first digit's decimal value by 16 and add the second digit's decimal value.
Example: #FF6A1A. Red channel: FF = (15 x 16) + 15 = 255. Green channel: 6A = (6 x 16) + 10 = 106. Blue channel: 1A = (1 x 16) + 10 = 26. Result: `rgb(255, 106, 26)` - a vivid orange. To go the other direction (RGB to HEX), divide each value by 16 to get the first digit's value, and take the remainder as the second digit's value, then convert both to hexadecimal. For 255: 255 / 16 = 15 remainder 15, which is FF. For 106: 106 / 16 = 6 remainder 10, which is 6A. This is arithmetic that a colour converter handles in milliseconds, but knowing the logic helps you spot errors when colour values look wrong.
When to Use Each Colour Format in CSS
All four formats are valid CSS in 2026. Choosing the right one for a given situation is a matter of readability, function, and workflow compatibility.
- Use HEX for static colour values in CSS and HTML. `color: #1a73e8` is concise and universally understood. It copies correctly from Figma and most design tools. Use it as the default for solid colours.
- Use RGBA when you need transparency. `rgba(0, 0, 0, 0.15)` for a subtle dark overlay, `rgba(255, 255, 255, 0.9)` for a frosted-glass background. HEX supports 8-digit notation for alpha (#RRGGBBAA), but RGBA is more widely understood and better supported in older code contexts.
- Use HSL for programmatic colour generation. If you are building a colour scale in JavaScript (stepping lightness from 10% to 90% at equal increments), HSL arithmetic is intuitive. Design token systems that generate semantic colour scales frequently use HSL under the hood.
- Use CSS colour variables (custom properties) for consistency. However you define a colour initially, store it as a CSS variable: `--colour-primary: #1a73e8`. Reference the variable everywhere, not the raw colour code. When you change the value, it updates site-wide.
Colour Spaces: sRGB, Display P3, and Wide-Gamut CSS
All the formats above operate in the sRGB colour space - the standard colour space used by virtually all web content since the web's inception. sRGB covers roughly 35% of all visible colours. Modern displays - iPhones, MacBooks with ProMotion, high-end monitors - support Display P3, a wider colour gamut that covers approximately 45% of visible colours. CSS Color Level 4 introduced syntax for specifying colours outside sRGB: `color(display-p3 0.9 0.4 0.1)` specifies an orange in the P3 space that is more saturated than the sRGB equivalent.
For most web projects, sRGB colours remain the correct default - they display correctly on all devices, with wide-gamut displays rendering them accurately within the sRGB portion of their range. Wide-gamut CSS colours are worth exploring for visual applications where maximum colour vibrancy on modern hardware matters, but they require careful fallback management for non-P3 displays.
OKLCH: The Modern CSS Colour Format to Know
OKLCH is a CSS Color Level 4 format that describes colour in a perceptually uniform colour space - meaning equal numeric changes produce equal perceived differences in colour, which neither sRGB nor HSL achieves. `oklch(lightness chroma hue)` - for example, `oklch(0.65 0.18 30)` for a warm orange. The 'L' in OKLCH means lightness behaves consistently across hues: an OKLCH lightness of 0.65 looks equally bright whether the hue is yellow, blue, or red. In HSL, a yellow at 50% lightness appears much brighter than a blue at 50% lightness due to how human vision perceives different wavelengths.
OKLCH matters most for gradient generation. A gradient between two colours in sRGB passes through a murky grey middle when the colours are complementary. The same gradient in OKLCH stays vibrant throughout because the interpolation follows perceptual uniformity. The CSS Gradient Generator at /tools/css-gradient-generator supports OKLCH gradients for exactly this reason.
Accessibility and Colour: WCAG Contrast Ratios
Converting between colour formats is frequently required when checking accessibility. The WCAG contrast ratio calculation (as defined at w3.org) uses relative luminance, which is calculated from the linear (not gamma-corrected) RGB values. Most accessibility tools convert HEX to relative luminance internally, but if you are doing the calculation manually you need the RGB values first.
WCAG 2.1 requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (18pt or 14pt bold) between text and its background. WCAG AAA requires 7:1 for normal text. Use the WCAG Contrast Checker at /tools/wcag-contrast-checker to verify any colour combination once you have your HEX or RGB values. The tool accepts any colour format and outputs the contrast ratio and pass/fail for AA and AAA compliance.
Picking Colours From Images and Working With Design Systems
Colour conversion is often triggered by needing to match a colour from an existing image or brand asset. The Color Picker from Image tool at /tools/color-picker-from-image lets you upload an image and click on any pixel to get its HEX, RGB, and HSL values instantly. This is useful for extracting brand colours from a logo, matching UI colours to a photograph, or reverse-engineering a colour scheme from a reference design.
For projects using Tailwind CSS, the built-in colour palette uses a specific set of HEX values with a consistent numeric scale (50 through 950). The Tailwind Color Palette tool at /tools/tailwind-color-palette shows the full palette with HEX, RGB, and HSL values for every swatch, so you can match your design colours to the nearest Tailwind equivalent without guessing class names.
How to Use the Searchlight Color Converter
- Open the tool at seosearchlight.com/tools/color-code-converter
- Enter your colour value in any supported format: HEX, RGB, RGBA, HSL, or OKLCH
- The tool converts to all other formats instantly in parallel output fields
- Copy the format you need for your current context
- Use the colour preview to verify the output matches your intended colour visually
- For accessibility checking, take the HEX or RGB output to /tools/wcag-contrast-checker
- For gradient generation, take the HEX output to /tools/css-gradient-generator
Free tool · no account needed
Try it free with Searchlight
Runs entirely in your browser. No uploads, no tracking, no paywall.
Convert Your Colour Codes →