Master different color formats (HEX, RGB, HSL, CMYK) and learn how to use them effectively in your web development projects. Complete guide with examples and best practices.
Understanding different ways to define colors in CSS
#RRGGBB
Hexadecimal color notation using 6 digits
#FF6B6B
Most common format for web design
rgb(red, green, blue)
Red, Green, Blue values from 0-255
rgb(255, 107, 107)
Good for programmatic color manipulation
hsl(hue, saturation%, lightness%)
Hue, Saturation, Lightness values
hsl(0, 100%, 71%)
Best for creating color variations
colorname
Predefined color names
crimson
Quick prototyping and basic colors
Common CSS properties that accept color values
Sets the text color of an element
color: #333333;
Applied to text content
Sets the background color of an element
background-color: rgba(255, 107, 107, 0.1);
Applied to element backgrounds
Sets the color of element borders
border-color: hsl(0, 100%, 71%);
Applied to border styling
Adds colored shadows to elements
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
Creates depth and visual effects
Sets the color of element outlines
outline-color: #FF6B6B;
Accessibility and focus states
Adds colored shadows to text
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
Text effects and readability
Professional techniques for managing colors in CSS
Define colors once and reuse throughout your stylesheet
:root { --primary-color: #FF6B6B; --secondary-color: #4ECDC4; } .button { background-color: var(--primary-color); }
Use semantic names that describe purpose, not appearance
/* Good */ --color-primary: #FF6B6B; --color-success: #10B981; --color-warning: #F59E0B; /* Avoid */ --red: #FF6B6B; --green: #10B981; --yellow: #F59E0B;
Leverage RGBA and HSLA for overlays and subtle effects
.overlay { background-color: rgba(0, 0, 0, 0.5); } .highlight { background-color: hsla(60, 100%, 50%, 0.2); }
Generate consistent color variations using HSL
:root { --blue-50: hsl(210, 100%, 95%); --blue-100: hsl(210, 100%, 90%); --blue-500: hsl(210, 100%, 50%); --blue-900: hsl(210, 100%, 20%); }
Ensure your color choices are accessible to all users
Ensure sufficient contrast between text and background colors
Requirement: WCAG AA: 4.5:1 for normal text, 3:1 for large text
Don't rely solely on color to convey information
Requirement: Use additional visual cues like icons or patterns
Provide clear focus indicators for keyboard navigation
Requirement: Use high-contrast colors for focus outlines
Design colors that work in both light and dark themes
Requirement: Test color combinations in different contexts
Continue learning with these related guides
Install DesignPicker to easily extract and work with colors in your web projects