Command Palette

Search for a command to run...

Back to all guides
Web & Security

Guide to Color Pickers and Color Conversion: HEX, RGB, HSL, and More

Understand color models and conversions for web development. Learn about HEX, RGB, HSL, CMYK, opacity channels, and how to pick the perfect colors for your projects.

9 min readPublished April 8, 2025

Introduction to Color Models

Color models are mathematical systems for representing colors in a standardized way. Each model describes color using different parameters, and understanding how they work is essential for anyone working with digital design, web development, or graphic design. Different color models are suited to different tasks: some are designed for screens, others for print, and others for human perception. The most common color models in web development are HEX, RGB, HSL, HSV, and CMYK, each with distinct strengths and use cases.

Choosing the right color model can significantly impact your workflow efficiency. For example, HSL is often more intuitive for designers because it separates hue, saturation, and lightness into independent controls, making it easy to create color palettes and variations. RGB is closer to how screens produce color and is the native format for CSS and canvas operations. HEX is a compact notation that is universally recognized and widely used in code. You can use our Color Picker and Converter to work with all these models interactively and convert between them instantly.

HEX Color Model

The HEX (hexadecimal) color model represents colors using a six-character code prefixed with a hash symbol. Each pair of characters represents the red, green, and blue channels, using hexadecimal digits (0-9 and A-F). For example, #FF5733 means red=FF (255), green=57 (87), blue=33 (51). HEX codes can also include an alpha channel for transparency, written as an eight-character code (#FF573380), where the last two characters represent opacity from 00 (fully transparent) to FF (fully opaque).

HEX is the most widely used color format in web development because of its compact syntax and universal browser support. Three-character shorthand is available when each pair consists of identical digits: #F53 is equivalent to #FF5533. HEX codes are commonly found in CSS files, design tools, and configuration files. Despite their ubiquity, HEX codes are not very intuitive for humans because they represent colors in the RGB model's channel values rather than in perceptually meaningful dimensions like hue or lightness.

RGB Color Model

The RGB (Red, Green, Blue) color model represents colors as three numbers ranging from 0 to 255, corresponding to the intensity of each color channel. Pure red is rgb(255, 0, 0), pure green is rgb(0, 255, 0), and pure blue is rgb(0, 0, 255). Black is rgb(0, 0, 0) — all channels at zero — and white is rgb(255, 255, 255) — all channels at maximum. The RGB model is additive, meaning colors are produced by combining light from red, green, and blue sources, which is how computer screens and mobile displays work.

RGB is the native color model for screens and is used extensively in CSS, canvas, WebGL, image processing, and video. The modern CSS syntax supports rgb() with optional alpha via rgba() or the modern rgb() function with a slash-separated alpha value: rgb(255 87 51 / 0.8). RGB values can also be expressed as percentages, where 100% equals 255. While RGB precisely describes how a color is produced on screen, it does not map well to human perception, making it less intuitive for tasks like creating harmonious palettes or adjusting lightness.

HSL Color Model

The HSL (Hue, Saturation, Lightness) color model represents colors using three perceptually meaningful parameters. Hue is the color type, expressed as an angle from 0 to 360 degrees on the color wheel (0 is red, 120 is green, 240 is blue, and 360 is back to red). Saturation describes the intensity of the color, from 0% (gray) to 100% (fully vivid). Lightness describes how bright or dark the color is, from 0% (black) to 100% (white), with 50% being the pure hue at full intensity.

HSL is the most intuitive model for designers because adjusting hue rotates through the color spectrum, adjusting saturation moves between gray and vivid color, and adjusting lightness moves between dark and bright. This makes it easy to create color variations: keeping the hue constant and varying lightness creates shades and tints of the same color, which is the foundation of cohesive design palettes. CSS supports hsl() and hsla() functions, with the modern syntax using a slash for alpha: hsl(15 100% 60% / 0.8).

HSV Color Model

The HSV (Hue, Saturation, Value) color model, also known as HSB (Hue, Saturation, Brightness), is similar to HSL but uses a different definition for the second and third parameters. In HSV, saturation ranges from 0% (white) to 100% (fully saturated), and value (or brightness) ranges from 0% (black) to 100% (full brightness). The key difference from HSL is how lightness and value are calculated: in HSV, a color with 100% value and 100% saturation is always fully vivid, while in HSL, a color with 100% lightness is always white regardless of saturation.

HSV is primarily used in color picker interfaces in design tools like Figma, Adobe Photoshop, and GIMP because it maps naturally to how users intuitively select colors — choosing a hue from the wheel, then adjusting saturation and brightness. While CSS does not natively support HSV, it is widely used internally by color picker components and is easily converted to and from RGB and HSL. Understanding HSV helps you use design tool color pickers more effectively.

CMYK Color Model

CMYK (Cyan, Magenta, Yellow, Key/Black) is a subtractive color model used in print production. Unlike RGB, which creates colors by adding light, CMYK creates colors by subtracting light from white paper using ink. Cyan, magenta, and yellow inks combine to absorb (subtract) red, green, and blue light respectively. A separate black ink channel (Key) is added because combining cyan, magenta, and yellow inks produces a muddy dark brown rather than a true black, and using black ink is more efficient and produces sharper text.

CMYK values are expressed as percentages from 0% to 100% for each channel. The CMYK gamut (range of representable colors) is smaller than the RGB gamut, which means some colors that look vivid on screen cannot be reproduced in print. When designing for both web and print, it is important to be aware of this limitation and check that your chosen colors fall within the CMYK gamut. Color conversion tools can highlight out-of-gamut colors before they go to print.

Converting Between Color Models

Converting between color models involves mathematical transformations. RGB to HEX is straightforward: each RGB channel (0-255) is converted to a two-digit hexadecimal number. RGB to HSL requires converting the RGB values to a range of 0-1, finding the minimum and maximum values to determine lightness, calculating the saturation based on the difference between max and min, and deriving the hue angle based on which channel is dominant. RGB to HSV follows a similar process but uses different formulas for saturation and value.

RGB to CMYK conversion is more complex because it involves mapping from the RGB additive gamut to the CMYK subtractive gamut, which may require clipping out-of-gamut colors. There is no single correct conversion because the result depends on the specific color profile of the output device (printer, paper type, ink coverage). For web development, the most common conversions are between HEX, RGB, and HSL, which are lossless and deterministic — every RGB color has an exact HEX and HSL representation, and vice versa.

Alpha Channels and Transparency

The alpha channel represents the opacity of a color, ranging from 0 (fully transparent) to 1 (fully opaque). All major CSS color models support alpha: rgba() for RGB, hsla() for HSL, and 8-digit HEX codes. Semi-transparent colors are essential for overlays, glassmorphism effects, layered backgrounds, and any UI element where content underneath should partially show through. When layering semi-transparent colors, the visual result depends on both the alpha value and the color of the elements behind the transparent element.

CSS provides several functions for working with alpha, including the modern color-mix() function (which can blend two colors) and relative color syntax (which can adjust the alpha of a base color). Understanding how alpha compositing works helps you predict how transparent colors will look when layered, preventing unexpected visual results in your designs. Always test transparent elements against varied backgrounds to ensure readability and visual consistency.

CSS Color Functions

Modern CSS provides powerful color functions that go beyond basic color notation. The color-mix() function blends two colors in a specified color space (srgb, oklch, etc.) at a given ratio. The color-contrast() function helps you find accessible foreground colors for a given background. Relative color syntax, using the from keyword, allows you to create variations of a base color by adjusting its channels: for example, hsl(from #ff5733 h s calc(l - 20%)) creates a darker version of the source color.

The newer OKLCH and OKLAB color spaces represent a significant improvement over HSL for perceptual uniformity. In HSL, adjusting lightness by a fixed amount does not produce a visually uniform change — some hues shift in unexpected ways. OKLCH and OKLAB were designed to be perceptually uniform, meaning equal numerical changes produce equal visual changes regardless of the hue. These modern spaces are now supported in all major browsers and are the recommended choice for new projects that need precise, perceptually consistent color manipulation.

Color Theory for Designers

Complementary Colors

Complementary colors sit directly opposite each other on the color wheel, separated by 180 degrees. These pairs create the strongest contrast and visual tension, making them effective for call-to-action buttons, highlights, and elements that need to stand out. Common complementary pairs include blue and orange, red and green, and purple and yellow. When using complementary colors, choose one as the dominant color and use the other as an accent to avoid visual overload.

Analogous Colors

Analogous colors are adjacent on the color wheel, typically within 30 to 60 degrees of each other. These palettes feel harmonious and cohesive because the colors share similar hue characteristics. Analogous schemes are common in nature and create serene, comfortable designs. To create an analogous palette, pick a base hue and select two to three adjacent hues. Vary the saturation and lightness of each color to create depth and hierarchy while maintaining the overall harmony.

Triadic Colors

Triadic color schemes use three colors evenly spaced around the color wheel, separated by 120 degrees. These schemes are vibrant and balanced, offering more variety than analogous schemes while maintaining visual harmony. A classic triadic scheme is red, yellow, and blue (the primary colors). When working with triadic schemes, let one color dominate and use the other two as secondary and accent colors to maintain a clear visual hierarchy and prevent the design from feeling chaotic.

WCAG Contrast Guidelines

The Web Content Accessibility Guidelines (WCAG) specify minimum contrast ratios between text and background colors to ensure readability for users with visual impairments. The contrast ratio is calculated based on the relative luminance of the two colors and ranges from 1:1 (identical colors) to 21:1 (black on white). WCAG 2.1 Level AA requires a minimum contrast ratio of 4.5:1 for normal text (under 18pt or 14pt bold) and 3:1 for large text (18pt or 14pt bold and above). Level AAA requires 7:1 for normal text and 4.5:1 for large text.

Meeting contrast requirements is not just about compliance — it improves readability for all users, including those viewing your site in bright sunlight, on low-quality screens, or with color vision deficiencies. When choosing colors for your UI, always check contrast ratios using tools like our color picker, browser dev tools, or dedicated accessibility checkers. If a color combination fails to meet the minimum ratio, adjust the lightness or saturation of one or both colors until the requirement is met.

Building Design System Palettes

A design system color palette provides a consistent, shared vocabulary for colors across an entire product or organization. A well-constructed palette typically includes primary, secondary, and accent colors, along with semantic colors for success, warning, error, and informational states. Each color should be defined at multiple shades — typically 50, 100, 200, 300, 400, 500, 600, 700, 800, and 900 — to support different use cases from subtle backgrounds to prominent text.

The most effective way to create a palette is to start with a single base hue in HSL, then generate lighter and darker variants by adjusting the lightness value. This ensures all shades share the same underlying hue, creating visual cohesion. Many design tools and CSS frameworks like Tailwind CSS follow this approach. Defining your palette using CSS custom properties allows you to support themes (light mode, dark mode, high-contrast mode) by swapping variable values rather than duplicating styles.

Key Takeaways

  • HEX, RGB, HSL, HSV, and CMYK are the most common color models — each suited to different tasks and workflows.
  • HEX is compact and universal, RGB maps directly to screen output, HSL is most intuitive for designers, and CMYK is required for print production.
  • Converting between HEX, RGB, and HSL is lossless and deterministic; converting to CMYK may clip out-of-gamut colors.
  • Alpha channels control transparency and are supported by all CSS color models — use them for overlays, glassmorphism, and layered effects.
  • Modern CSS color functions like color-mix(), relative color syntax, and OKLCH/OKLAB spaces provide powerful tools for perceptually consistent color manipulation.
  • WCAG contrast guidelines require minimum ratios of 4.5:1 for normal text and 3:1 for large text at Level AA.
  • Design system palettes should define each color at multiple shades and use CSS custom properties for theme support.

Frequently Asked Questions

What is the difference between HSL and HSV?

While both models use hue, saturation, and a brightness dimension, HSL and HSV define saturation and brightness differently. In HSL, lightness of 100% is always white and 0% is always black, regardless of saturation. In HSV, value of 100% means the color is at full brightness, and saturation of 0% means white. This means that in HSL, a fully saturated color at 50% lightness is the pure hue, while in HSV, a fully saturated color at 100% value is the pure hue. The practical difference is that HSV is more intuitive for color picker interfaces, while HSL is more useful for programmatically generating shades and tints.

How do I ensure my color choices are accessible?

Use a contrast checker tool to verify that your foreground and background color combinations meet WCAG contrast ratios — at minimum 4.5:1 for normal text and 3:1 for large text. Test your palette against both light and dark backgrounds, and consider users with color vision deficiencies by ensuring that information is not conveyed by color alone. Use tools like our color picker with built-in contrast checking to streamline this process during design and development.

Should I use HEX, RGB, or HSL in my CSS?

All three formats are valid and fully supported. Use HEX for simple, static colors where you just need to specify a value quickly. Use RGB when you need to work with individual channel values or alpha transparency. Use HSL when you need to create variations of a color (lighter, darker, more or less saturated) because HSL's parameters map intuitively to perceptual adjustments. For design systems and theme variables, HSL or the newer OKLCH format are the best choices because they allow programmatic generation of color scales.

Try the Guide to Color Pickers and Color Conversion tool

Put what you learned into practice with our free online tool.

Related Guides