โ† Back to Tools
๐ŸŽจ Image & Text

Color Codes for Web Design โ€” HEX, RGB, HSL & CSS Guide

By AutoCalcConvert ยท 6 min read ยท September 2026

Color in web design is expressed through code, and understanding the different color formats helps you work more efficiently and build better color systems. Each format has distinct strengths โ€” HEX for simplicity, RGB for programmatic manipulation, HSL for intuitive color relationships, and oklch for perceptually uniform modern design systems.

HEX Colors

HEX (hexadecimal) colors are the most common format in CSS and web design tools. A HEX color is a six-character string preceded by #, where each pair of characters represents red, green, and blue values in base-16 (0-9 and A-F).

#RRGGBB where each pair ranges from 00 (0) to FF (255)

#FF0000 = pure red ยท #00FF00 = pure green ยท #0000FF = pure blue
#000000 = black ยท #FFFFFF = white ยท #808080 = medium gray

A three-character shorthand exists when both characters in each pair are identical: #FF0000 โ†’ #F00, #AABBCC โ†’ #ABC. HEX also supports an optional two-character alpha: #FF000080 = 50% transparent red.

RGB and RGBA

RGB expresses colors as three values 0-255 for red, green, and blue. RGBA adds a fourth value (0-1) for opacity. RGB is useful when you need to manipulate color values programmatically or set transparency.

ColorHEXRGB
Pure red#FF0000rgb(255, 0, 0)
Navy blue#001F5Brgb(0, 31, 91)
50% transparent black#00000080rgba(0, 0, 0, 0.5)
Coral#FF6B6Brgb(255, 107, 107)

HSL โ€” The Designer-Friendly Format

HSL (Hue, Saturation, Lightness) is the most intuitive format for designers building color systems. Hue is a position on the color wheel (0-360 degrees). Saturation is the intensity from gray (0%) to full color (100%). Lightness ranges from black (0%) to white (100%).

HSL makes it easy to create color variations: to darken a button on hover, just decrease L. To create a muted version, decrease S. To find a complementary color, add 180 to H. This predictability is why design systems like Tailwind CSS expose HSL-based color variables.

AdjustmentEffectExample
Change HDifferent color, same moodBlue โ†’ Purple
Decrease SMore muted/neutralVibrant โ†’ Muted
Decrease LDarker shadeMedium โ†’ Dark
Increase LLighter tintMedium โ†’ Light

Color Accessibility

WCAG (Web Content Accessibility Guidelines) requires a minimum contrast ratio between text and background: 4.5:1 for normal text and 3:1 for large text (18pt+ or 14pt+ bold). Approximately 8% of men and 0.5% of women have some form of color vision deficiency, with red-green color blindness being most common. Always test color combinations for contrast and never rely on color alone to convey information.

Common CSS Color Tips

  • Use CSS custom properties (variables) for your color system: --primary: #3b5bdb;
  • currentColor inherits the element's color value โ€” useful for icon SVGs
  • transparent is equivalent to rgba(0,0,0,0)
  • oklch() is the modern color format with perceptually uniform lightness โ€” increasingly supported in modern browsers

Convert any color between HEX, RGB, and HSL instantly.

Open Color Code Converter โ†’

Frequently Asked Questions

Which color format should I use in CSS?
Use HEX for static colors in design systems (most readable). Use RGBA when you need opacity. Use HSL when building color scales or need programmatic color relationships. All are valid CSS โ€” choose based on your workflow.
What are named CSS colors?
CSS supports 140 named colors like red, blue, tomato, cornflowerblue, and rebeccapurple (named after the daughter of CSS Working Group member Eric Meyer). They're convenient for quick prototyping but too imprecise for production design systems.
How do I check if my color contrast passes WCAG?
Use a contrast checker tool โ€” input your foreground and background colors and it calculates the ratio. A ratio of 4.5:1 or higher passes AA for normal text. Our color converter can help you find and adjust your HEX or RGB values.