Practical guide to choosing and implementing color codes for web design. Learn about HEX, RGB, HSL, color accessibility, and creating effective color schemes for websites.
Selecting the right colors and color codes is crucial for effective web design. This guide covers everything you need to know about choosing, implementing, and managing colors for websites, from color formats to accessibility requirements.
Format: #RRGGBB (e.g., #FF5733)
Pros:
Cons:
When to use: Default choice for most web projects
Format: rgb(255, 87, 51) or rgba(255, 87, 51, 0.8)
Pros:
Cons:
When to use: When you need transparency or working with JavaScript
Format: hsl(9, 100%, 60%) or hsla(9, 100%, 60%, 0.8)
Pros:
Cons:
When to use: Design systems, color variations, modern CSS
| Use Case | Best Format | Example |
|---|---|---|
| Static colors | HEX | #3498db |
| Transparency needed | RGBA or HSLA | rgba(52, 152, 219, 0.8) |
| Color variations | HSL | hsl(204, 70%, 53%) |
| Design system | HSL with CSS variables | --primary-hue: 204 |
| JavaScript manipulation | RGB or HSL | rgb(52, 152, 219) |
| Legacy browser support | HEX | #3498db |
Your primary color represents your brand and is used most frequently.
Considerations:
Example Primary Colors:
Generate lighter and darker versions of your primary color.
Using HSL (Recommended):
/* Primary */
--primary: hsl(210, 100%, 50%);
/* Lighter variations */
--primary-100: hsl(210, 100%, 95%);
--primary-200: hsl(210, 100%, 85%);
--primary-300: hsl(210, 100%, 75%);
/* Darker variations */
--primary-600: hsl(210, 100%, 40%);
--primary-700: hsl(210, 100%, 30%);
--primary-800: hsl(210, 100%, 20%);Secondary colors complement your primary color.
Color Harmony Methods:
Greys for text, backgrounds, and borders.
/* Neutral greys */
--grey-50: #F9FAFB;
--grey-100: #F3F4F6;
--grey-200: #E5E7EB;
--grey-300: #D1D5DB;
--grey-400: #9CA3AF;
--grey-500: #6B7280;
--grey-600: #4B5563;
--grey-700: #374151;
--grey-800: #1F2937;
--grey-900: #111827;Colors for success, warning, error, and info states.
/* Semantic colors */
--success: #10B981; /* Green */
--warning: #F59E0B; /* Orange */
--error: #EF4444; /* Red */
--info: #3B82F6; /* Blue */| Level | Normal Text | Large Text | UI Components |
|---|---|---|---|
| AA (Minimum) | 4.5:1 | 3:1 | 3:1 |
| AAA (Enhanced) | 7:1 | 4.5:1 | 4.5:1 |
Large Text Definition: 18pt+ regular or 14pt+ bold
Use our Contrast Checker to verify your color combinations meet WCAG standards.
Common Mistakes:
Best Practices:
.button {
background-color: #3498db;
color: #ffffff;
}Pros: Simple, direct
Cons: Hard to maintain, no consistency
:root {
--primary: #3498db;
--primary-dark: #2980b9;
--text: #333333;
--background: #ffffff;
}
.button {
background-color: var(--primary);
color: var(--background);
}
.button:hover {
background-color: var(--primary-dark);
}Pros: Easy to maintain, consistent, supports theming
Cons: No IE11 support
:root {
--primary-h: 204;
--primary-s: 70%;
--primary-l: 53%;
--primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
--primary-light: hsl(var(--primary-h), var(--primary-s), 70%);
--primary-dark: hsl(var(--primary-h), var(--primary-s), 35%);
}
.button {
background-color: var(--primary);
}
.button:hover {
background-color: var(--primary-dark);
}Pros: Ultimate flexibility, easy variations, perfect for design systems
Cons: More complex setup
:root {
--background: #ffffff;
--text: #1a202c;
--primary: #3498db;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #1a202c;
--text: #ffffff;
--primary: #5dade2;
}
}
body {
background-color: var(--background);
color: var(--text);
}[data-theme="light"] {
--background: #ffffff;
--text: #1a202c;
}
[data-theme="dark"] {
--background: #1a202c;
--text: #ffffff;
}Single hue with varying lightness/saturation
--primary: hsl(210, 100%, 50%);
--primary-light: hsl(210, 100%, 70%);
--primary-lighter: hsl(210, 100%, 90%);
--primary-dark: hsl(210, 100%, 30%);Two opposite colors on color wheel
--primary: hsl(210, 100%, 50%); /* Blue */
--secondary: hsl(30, 100%, 50%); /* Orange (210 + 180) */Three evenly spaced colors
--primary: hsl(0, 100%, 50%); /* Red */
--secondary: hsl(120, 100%, 50%); /* Green (0 + 120) */
--tertiary: hsl(240, 100%, 50%); /* Blue (0 + 240) */| Color | Emotion/Association | Best For |
|---|---|---|
| Blue | Trust, stability, calm | Tech, finance, healthcare |
| Green | Growth, health, nature | Eco, health, finance |
| Red | Energy, urgency, passion | Food, sales, entertainment |
| Yellow | Optimism, warmth, caution | Children, food, warnings |
| Purple | Luxury, creativity, wisdom | Beauty, luxury, creative |
| Orange | Enthusiasm, creativity, fun | Sports, entertainment, tech |
| Black | Sophistication, power, elegance | Luxury, fashion, tech |
| White | Purity, simplicity, cleanliness | Healthcare, minimal design |
Explore these comprehensive pillar articles related to How to Choose Color Codes for Web Design
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
Comprehensive guide to complementary colors - opposing hues on the color wheel that create maximum visual contrast, dynamic tension, and powerful design impact through scientific color relationships and perceptual phenomena.
Comprehensive guide to analogous color schemes - adjacent hues on the color wheel that create natural harmony, visual cohesion, and sophisticated design solutions through subtle color relationships and graduated transitions.
Comprehensive guide to triadic color schemes - three colors evenly spaced around the color wheel that create balanced, vibrant, and dynamic visual compositions with mathematical precision and artistic appeal.
Discover more about How to Choose Color Codes for Web Design and related color theory concepts
Comprehensive guide to analogous color schemes - adjacent hues on the color wheel that create natural harmony, visual cohesion, and sophisticated design solutions through subtle color relationships and graduated transitions.
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
Comprehensive guide to complementary colors - opposing hues on the color wheel that create maximum visual contrast, dynamic tension, and powerful design impact through scientific color relationships and perceptual phenomena.
A comprehensive guide to monochromatic color schemes - sophisticated single-hue harmonies that create unified visual experiences through systematic variations in saturation, lightness, and tonal relationships, essential for elegant design compositions, brand consistency, and advanced color theory applications requiring cohesive aesthetic unity.
A comprehensive guide to split-complementary color schemes - sophisticated three-color harmonies that combine a base color with two colors adjacent to its complement, creating balanced visual contrast with reduced tension compared to direct complementary pairs, essential for refined design compositions, brand identity systems, and advanced color theory applications.
A comprehensive guide to tetradic color schemes - sophisticated four-color harmonies that use two complementary pairs arranged in rectangular or square formations on the color wheel, providing maximum color variety while maintaining structured relationships essential for dynamic design compositions, brand systems, and advanced color theory applications.
Discover more color terminology and concepts in our comprehensive glossary.
Browse Full Glossary