Color Conversion: HEX, RGB, HSL, and CMYK
Every color on your screen can be described in multiple ways. Whether you are writing CSS, designing a logo, or preparing files for print, understanding color models helps you choose the right format.
This guide covers the most common color formats and when to use each one.
HEX Colors
HEX is the most common color format in web development. It uses a 6-digit code preceded by a hash symbol.
#FF5733Each pair of digits represents the intensity of red, green, and blue on a scale from 00 to FF.
#FF 57 33
R G B#FF5733 means maximum red, moderate green, and low blue. Shorthand HEX is also supported in CSS: #FFF is the same as #FFFFFF.
RGB Colors
RGB stands for red, green, and blue. Each channel ranges from 0 to 255.
color: rgb(255, 87, 51);RGB contains the same basic channel data as HEX, just written in decimal form. #FF5733 equals rgb(255, 87, 51).
RGBA adds a transparency channel from 0 to 1:
color: rgba(255, 87, 51, 0.8);Use RGB or RGBA when you need transparency, dynamic color calculations, canvas work, or JavaScript-friendly channel values.
HSL Colors
HSL stands for hue, saturation, and lightness. It is often easier for humans to adjust than raw RGB values.
color: hsl(14, 100%, 60%);- Hue is the position on the color wheel from 0 to 360.
- Saturation describes how vivid the color is.
- Lightness describes how bright or dark the color is.
HSL is useful for design systems because you can create related shades by changing only lightness or saturation.
.primary {
color: hsl(210, 80%, 50%);
}
.primary-light {
color: hsl(210, 80%, 70%);
}
.primary-dark {
color: hsl(210, 80%, 30%);
}HEX vs RGB vs HSL in CSS
The best format depends on what you are editing.
| Task | Useful format | Why |
|---|---|---|
| Copying a brand color into CSS | HEX | Compact and widely recognized |
| Adjusting opacity | RGB or HSL with alpha | Alpha values are easy to read |
| Creating hover states | HSL | Lightness can be adjusted predictably |
| Working with design tokens | HSL or RGB channels | Easier to generate variants |
| Matching values from a design file | HEX or RGB | Many tools expose both |
For example, if you only need a fixed color, HEX is clean. If you need to make the same color lighter on hover, HSL often makes the change easier to reason about.
CMYK Colors
CMYK stands for cyan, magenta, yellow, and key black. It is a subtractive color model used primarily for print.
Unlike RGB, which is used for screens, CMYK is designed for ink on paper. Bright screen colors often look duller in print, so always check a CMYK proof before sending important work to a printer.
Screen Colors and Print Colors Differ
Web colors are usually defined in RGB because screens emit light. Print colors use ink, paper, and printer profiles. A color that looks vivid on a monitor may not be printable with the same intensity.
This matters when a campaign uses the same brand color on:
- a website
- a PDF
- a printed flyer
- a product label
- an event banner
Use RGB, HEX, or HSL for web implementation. Use CMYK values from a brand guide or print designer for print production. Do not assume a direct conversion will always preserve the visual result.
Quick Comparison
| Format | Example | Best for |
|---|---|---|
| HEX | #FF5733 | CSS, HTML, web design |
| RGB | rgb(255, 87, 51) | CSS transparency and JavaScript |
| HSL | hsl(14, 100%, 60%) | Design systems and color variants |
| CMYK | cmyk(0, 66, 80, 0) | Print design |
Named CSS Colors
CSS also supports named colors for quick prototyping.
color: coral;
color: steelblue;
color: midnightblue;Named colors are convenient, but HEX, RGB, or HSL are usually better for production because they are more precise.
Alpha Transparency
Modern CSS supports alpha values in several forms:
background: rgba(255, 87, 51, 0.2);
background: hsl(14 100% 60% / 20%);Transparency is useful for overlays, focus states, shadows, borders, and disabled UI. Be careful when placing transparent colors over changing backgrounds. The final perceived color depends on what sits underneath.
For design systems, test translucent colors on both light and dark surfaces. A border that looks subtle on white may be almost invisible on a dark panel.
Contrast and Accessibility
Color conversion tells you how a color is represented. It does not tell you whether the color is readable.
Before using a color for text, buttons, form labels, or charts, check contrast against the actual background. A beautiful accent color may be fine for an icon but too low-contrast for body text.
Common practical rules:
- use strong contrast for text and controls
- do not rely on color alone to show errors or success
- test hover and disabled states separately
- check dark mode variants, not only light mode
- verify chart colors remain distinguishable
Conversion is one step in the workflow. Visual testing is still required.
Convert Colors Instantly
Use the Color Converter to convert between HEX, RGB, and HSL formats with a live preview. When you are planning layouts around those colors, the CSS Unit Converter can help translate spacing and sizing values too.
Practical Color Workflow
- Start with the source color from the design file or brand guide.
- Convert it to the format your CSS uses.
- Create hover, active, muted, and background variants.
- Test contrast on real UI surfaces.
- Check dark mode if the site supports it.
- Keep final values in design tokens or CSS variables.
This keeps color decisions consistent across components instead of scattering one-off values through stylesheets.
Conclusion
Use HEX for simple web colors, RGB when you need channel values or transparency, HSL for design systems, and CMYK for print. Knowing how the formats relate makes it much easier to move between design tools, CSS, and production assets.
Related Guides
- CSS units guide: px, em, rem, vw, and vh helps pair color tokens with layout and spacing tokens.
- CSS unit conversion for responsive design is useful when translating static design specs into responsive CSS.
- Browse related utilities in the Design / Frontend Tools collection.
Related QuickToolFlow Tools
- Color Converter for HEX, RGB, and HSL conversion.
- CSS Unit Converter for px, rem, em, vw, and vh calculations.
- Lorem Image Placeholder for testing image blocks with custom placeholder colors.
Keep going