Color Everything in CSS – Simple Guide
June 26, 2025Color Everything in CSS – Simple Guide
Today we’re diving into CSS colors: how to define them, especially with modern methods like lab() and oklch().
1. What’s a “color”?
Color isn’t a physical property. It’s a perception created by our brain when light hits our eyes.
2. Color Spaces
These are 3D mappings of color. Some examples:
sRGB: The default space on most screens.CIELAB&Oklab: Offer more perceptually uniform color transitions.color(display-p3 ...): Supports a wider variety of colors on modern displays.
3. Color Models
Like RGB or HSL—numeric representations. They need a color space to mean anything.
4. Color Gamuts
It’s the range of colors a space can represent. If a display can’t show a color, it's “out of gamut”.
5. CSS Color Functions
rgb(), hsl(), hwb(): For basic sRGB colors.lab(), lch(): For CIELAB space.oklab(), oklch(): For Oklab space.color(), color-mix(): To tap into spaces like display‑p3, rec2020, etc.
Code examples:
.box-srgb {
background: rgb(255, 100, 50);
}
.box-oklab {
background: oklab(70% 0.05 -0.10);
}
.box-display-p3 {
background: color(display-p3 1 0.2 0.3);
}
TL;DR
- Color space = how colors are mapped.
- Color model = numeric representation, needs a space.
- Color gamut = available color range.
- Modern CSS lets us use all these with proper functions.
Blog
Aug 09, 2025
Object-Oriented Programming (OOP) is a modern software development approach that divides an application into units called Objects that interact with...
Jun 17, 2025
React Labs: View Transitions & Activity Published April 23, 2025 by Ricky Hanlon. React Labs is sharing two new experimental featu...
Jul 27, 2025
Here’s a complete breakdown of essential tools to level up your Laravel development: Inertia.js v2, View Creators, and the Laravel HLS package...
Jul 26, 2025
1. Origins: Born Inside Facebook In 2011, Facebook engineers faced the increasing complexity of building interactive UIs at scale. They developed...
Jul 16, 2025
🌐 Mastering Modern CSS: The Power of if(), Popover Hints, and Smart Styling CSS is getting smarter. In this guide, we’ll explore how the new...
Jul 02, 2025
Bypassing $fillable Safely with forceFill() in Laravel Ever used create() in Laravel and noticed some fields like role or status didn’t save? T...