Colors

๐ŸŽจ CSS3+ ๐ŸŸข Chapter 11 of 49 ๐Ÿ“‚ Phase 04: Values, Units & Colors ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Named Colors ยท Hex ยท RGB ยท RGBA ยท HSL ยท HSLA ยท Modern Functions ยท Opacity ยท Transparency ยท Contrast ยท Theme Colors ยท CSS Variables
Welcome to Chapter 11: Colors โ€” part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1CSS Color Formats
FormatExampleNotes
Namedred, tomato140+ keywords
Hex#2563eb, #fffMost common in design
RGB / RGBArgb(37, 99, 235)Alpha for transparency
HSL / HSLAhsl(217, 91%, 53%)Intuitive hue/sat/light
Modernoklch(), color-mix()CSS Color Level 4+
2Opacity, Transparency & Color Contrast
.overlay {
  background-color: rgba(0, 0, 0, 0.5);
}

.card {
  opacity: 0.9; /* Affects entire element including children */
}

.text {
  color: hsl(215 16% 47% / 0.8); /* Modern alpha syntax */
}

Color contrast: WCAG guidelines โ€” text ki minimum 4.5:1 contrast ratio (normal text). Accessibility tools and DevTools contrast checker use cheyandi.

3Theme Colors with CSS Variables
CSS โ€” Color Variablesโ–ถ Try in Editor
:root {
  --primary-color: #2563eb;
  --text-color: #1f2937;
  --surface-color: #ffffff;
  --muted-color: #6b7280;
}

body {
  color: var(--text-color);
  background-color: var(--surface-color);
}

.btn-primary {
  background-color: var(--primary-color);
  color: #fff;
}

/* Dark theme override */
[data-theme="dark"] {
  --text-color: #f9fafb;
  --surface-color: #111827;
}
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy ยท CSS Complete Roadmap ยท Last updated August 2026