Stop using the legacy color syntax

Kevin Powell · Beginner ·🌐 Frontend Engineering ·7mo ago

Key Takeaways

The video discusses the modern CSS color syntax, encouraging developers to stop using the legacy color syntax and adopt the new space-separated syntax with a forward slash for alpha values, and explores the benefits of using new color functions like OKLCH and LAB.

Full Transcript

Hi there, my friend and friend. Did you know that you don't need the A in RGBA or HSLA to add an alpha value to your colors? And you actually haven't needed this since about 2019. And if you're going to remove the A, you can also remove the commas while you're at it. Yeah, the the commas are completely optional now and they're actually part of what we call the legacy syntax when it comes to writing colors in CSS. Now, there's a really important thing though that if you do remove the commas, you have to change how you're adding in the opacity uh or the alpha value. When we're doing that now, instead of having a comma cuz we don't have comma separations and we don't put a space there, we actually put a forward slash. And some people have complained to me about this saying that this is adding inconsistency to how things work in CSS cuz comma-separated things are all over the place in CSS, but first of all, that's not true. Uh space separation is very common in CSS and the forward slash is actually something that's being used in a lot of places now in CSS. One of the first ones that comes to mind for me is when we're adding alt text to the content property on pseudo elements and other things like that. Uh we're also doing that with a forward slash and there are a few other use cases as well. And it's simply a nice visual indicator that this is a different thing from the actual color values. You have color values forward slash and the alpha value and it makes a nice clean visual separation between the two of them. Now, you might be saying, "I don't want to change." And before we get to the why, I think you should get used to the new color syntax, the space separation instead. The first thing I want to say is I wouldn't go into old projects and update things. This is not worth a refactor uh and the old way still works and will continue to work, which of course begs the question, why should you change going forward? And there's actually a few different reasons uh that I I think that you should. The first one is we have a lot of new ways to write colors in CSS now. Uh for example, there's OKLCH, there's LAB, there's the color function. And if we're using these new color functions instead of using the HSL or RGB, and we'll talk about why there's benefits to to those new ones over those other ones. Uh if you are using those, they don't actually support the comma-separated syntax. They only support the space-separated version. So, if you're going to be using them, then you probably want to move forward and get used to it just so there's a consistency within your own projects and just so you have the habit of working with the space version with the forward slash in it. And you might be going, "But Kevin, I just copy and paste values from design files. Why do I care what syntax I'm using?" And if that's the case, that's perfectly fine. It will continue to work, but there's a few reasons anyway, as I said, you might want to be using OKLCH or the color feature at one point because you might get a client who's asking you for a more vibrant brand color. They have a bright green and on there, you're using HSL and you're getting it as bright green as you possibly can and they're like, "It's not bright enough." And you're like, "Oh, it's all we can do." That's not true. So, the color features like OKLCH, color, LAB, all of these, they have much wider color gamuts. And that's sort of the fancy way of saying that they can make more colors than sRGB can when sRGB is what we've been using traditionally with uh our RGB function or our HSL function. And we can actually see here on the screen right now that if I switch this green over from an HSL to an OKLCH in the dev tools, I can get this color picker that shows up and it shows me where we go into the wider color gamut. Now, some screens might not support this wider color gamut, but that's completely fine. Most fancy phones these days will, so the client will be very happy on theirs. Uh a lot of desktop monitors as well, but on ones that don't support that higher gamut, they're just going to get the fallback color anyway. So, everyone will be completely fine. But maybe more importantly than just getting that bright color, uh the space-separated syntax is also what's used when it comes to relative colors, which even if you're just copying and pasting, you can definitely take advantage of uh relative colors in a really big way. And relative colors might be one of my favorite new features and most used new features of CSS uh these days. Quickly before I get into them, I do want to let you know that if you want to dive deeper into color, this video is actually inspired from an article that I wrote for Piccalilli, which is linked down below. It's the pragmatic guide to colors. There's two parts to it. Uh if you're just a copy and paster, there's a whole bunch of awesome stuff that these new color features uh open the doors for, which is what part one's all about. And if you want to dive even deeper, part two dives into some of the cool color manipulation and other things that we can be doing if you want to create your own design systems and other stuff within the browser. And just to let you know, Piccalilli's a really great place for front-end content in general and they've also got courses, too. A lot of you've been asking me for more JavaScript content and if that's the case and you what you're after more, maybe do consider checking out their JavaScript for everyone course. Uh this is not a sponsored bit at all. I just want to help spread the word on uh the fantastic stuff that Andy and the team over there is currently doing. Lots of really good articles and other stuff, not just mine. So, definitely check that out and if you're into courses, go and look at those as well. And if you haven't run off yet and you want to learn a little bit more about relative colors, let's dive in here and take a look uh at this demo that I have set up and we're just going to look at a really maybe my favorite use case of relative colors. Uh where up here, I have my root. I have some defined colors and I have this color brand. We'll use this as the example, but it would work with any of these. And over here, I'm setting a background color using my color brand. What if I want this to have a little bit of transparency in it? That would always be a little bit annoying. Traditionally speaking, you have to have another

Original Description

Get rid of that "a" and drop those commas! 🔗 Links ✅ A pragmatic guide to modern CSS colours - part one: https://piccalil.li/blog/a-pragmatic-guide-to-modern-css-colours-part-one/ ✅ A pragmatic guide to modern CSS colours - part two: https://piccalil.li/blog/a-pragmatic-guide-to-modern-css-colours-part-two/ ✅ Piccalilli courses: https://piccalil.li/courses/ ✉ Keep up to date with everything I'm up to https://www.kevinpowell.co/newsletter 💬 Come hang out with other devs in my Discord Community https://discord.gg/nTYCvrK ⭐ Are you a beginner? HTML & CSS for absolute beginners is for you: https://learn.kevinpowell.co 🎓 Start writing CSS with confidence with CSS Demystified: [https://cssdemystified.com](https://cssdemystified.com/) 🚀 Already mastered CSS? Check out my advanced course, Beyond CSS: https://www.beyondcss.dev/ ⌚ Timestamps 00:00 - Introduction 01:45 - probably not worth refactoring 02:00 - Why we need to get used to the space-separated syntax 02:50 - Wider color gamuts with the new ones 03:50 - Relative colors use the space-separated syntax #css --- Help support my channel 👨‍🎓 Get a course: https://www.kevinpowell.co/courses 👕 Buy a shirt: https://cottonbureau.com/people/kevin-powell 💖 Support me on Patreon: https://www.patreon.com/kevinpowell or through YT memberships: https://youtube.com/@KevinPowell/join --- 🧑‍💻 My editor: VS Code - https://code.visualstudio.com/ 🌈 My theme: One Dark Pro Var Night 🔤 My font: Cascadia Code --- I'm on some other places on the internet too! If you'd like a behind the scenes and previews of what's coming up on my YouTube channel: Bluesky: https://bsky.app/profile/kevinpowell.co Codepen: https://codepen.io/kevinpowell/ Github: https://github.com/kevin-powell --- And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Kevin Powell · Kevin Powell · 0 of 60

← Previous Next →
1 How to create an awesome navigation bar with HTML & CSS
How to create an awesome navigation bar with HTML & CSS
Kevin Powell
2 Improve your CSS by Keepin' it DRY
Improve your CSS by Keepin' it DRY
Kevin Powell
3 HTML & CSS for Beginners Part 6: Images
HTML & CSS for Beginners Part 6: Images
Kevin Powell
4 HTML & CSS for Beginners Part 7: File Structure
HTML & CSS for Beginners Part 7: File Structure
Kevin Powell
5 HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
Kevin Powell
6 HTML & CSS for Beginners Part 5: Links
HTML & CSS for Beginners Part 5: Links
Kevin Powell
7 HTML & CSS for Beginners Part 3: Paragraphs and Headings
HTML & CSS for Beginners Part 3: Paragraphs and Headings
Kevin Powell
8 HTML and CSS for Beginners Part 1: Introduction to HTML
HTML and CSS for Beginners Part 1: Introduction to HTML
Kevin Powell
9 HTML and CSS for Beginners Part 2: Building your first web page!
HTML and CSS for Beginners Part 2: Building your first web page!
Kevin Powell
10 HTML & CSS for Beginner Part 8: Introduction to CSS
HTML & CSS for Beginner Part 8: Introduction to CSS
Kevin Powell
11 HTML & CSS for Beginners Part 9: External CSS
HTML & CSS for Beginners Part 9: External CSS
Kevin Powell
12 HTML & CSS for Beginners Part 10: Divs & Spans
HTML & CSS for Beginners Part 10: Divs & Spans
Kevin Powell
13 HTML & CSS for Beginners Part 11: Classes & IDs
HTML & CSS for Beginners Part 11: Classes & IDs
Kevin Powell
14 HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
Kevin Powell
15 HTML & CSS for Beginners Part 13: Background Images
HTML & CSS for Beginners Part 13: Background Images
Kevin Powell
16 HTML & CSS for Beginners Part 14: Style Text with CSS
HTML & CSS for Beginners Part 14: Style Text with CSS
Kevin Powell
17 HTML & CSS for Beginners Part 15: How to style links
HTML & CSS for Beginners Part 15: How to style links
Kevin Powell
18 HTML & CSS for Beginners Part 16: CSS selectors and Specificity
HTML & CSS for Beginners Part 16: CSS selectors and Specificity
Kevin Powell
19 HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
Kevin Powell
20 HTML & CSS for Beginners Part 18: How Floats and Clears work
HTML & CSS for Beginners Part 18: How Floats and Clears work
Kevin Powell
21 HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
Kevin Powell
22 HTML & CSS for Beginners Part 20: How to center a div
HTML & CSS for Beginners Part 20: How to center a div
Kevin Powell
23 HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
Kevin Powell
24 HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
Kevin Powell
25 How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
Kevin Powell
26 How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
Kevin Powell
27 How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
Kevin Powell
28 How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
Kevin Powell
29 How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
Kevin Powell
30 Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Kevin Powell
31 End of the year upate and what's coming to my channel to start the new year
End of the year upate and what's coming to my channel to start the new year
Kevin Powell
32 Create a CSS only Mega Dropdown Menu
Create a CSS only Mega Dropdown Menu
Kevin Powell
33 CSS Tutorial: Outline and Outline Offset
CSS Tutorial: Outline and Outline Offset
Kevin Powell
34 CSS Blending Modes
CSS Blending Modes
Kevin Powell
35 Parallax effect | 2 different ways to add it with jQuery
Parallax effect | 2 different ways to add it with jQuery
Kevin Powell
36 CSS Units: vh, vw, vmin, vmax #css #responsive #design
CSS Units: vh, vw, vmin, vmax #css #responsive #design
Kevin Powell
37 How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
Kevin Powell
38 100 Subscribers speed coding bonus video
100 Subscribers speed coding bonus video
Kevin Powell
39 How to Create a Website - Complete workflow | Part 02: The Markup #HTML
How to Create a Website - Complete workflow | Part 02: The Markup #HTML
Kevin Powell
40 How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
Kevin Powell
41 How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
Kevin Powell
42 How to Create a Website - Complete workflow | Part 05: Typography & Buttons
How to Create a Website - Complete workflow | Part 05: Typography & Buttons
Kevin Powell
43 How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
Kevin Powell
44 How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
Kevin Powell
45 Redesigning & Coding My Website #CreateICG
Redesigning & Coding My Website #CreateICG
Kevin Powell
46 How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
Kevin Powell
47 How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
Kevin Powell
48 How to Create a Website - Complete workflow | Part 09: The CTA and Footer
How to Create a Website - Complete workflow | Part 09: The CTA and Footer
Kevin Powell
49 How to Create a Website - Complete workflow | Part 10: Making it responsive
How to Create a Website - Complete workflow | Part 10: Making it responsive
Kevin Powell
50 How to Create a Website - Complete workflow | Part 11: Making it responsive con't
How to Create a Website - Complete workflow | Part 11: Making it responsive con't
Kevin Powell
51 How to Create a Website - Complete workflow | Part 12: Putting the site online
How to Create a Website - Complete workflow | Part 12: Putting the site online
Kevin Powell
52 Create a Custom Grid System with CSS Calc() and Sass
Create a Custom Grid System with CSS Calc() and Sass
Kevin Powell
53 CSS em and rem explained #CSS #responsive
CSS em and rem explained #CSS #responsive
Kevin Powell
54 Should you use Bootstrap?
Should you use Bootstrap?
Kevin Powell
55 How to add Smooth Scrolling to your one page website with jQuery
How to add Smooth Scrolling to your one page website with jQuery
Kevin Powell
56 Let's learn Bootstrap 4
Let's learn Bootstrap 4
Kevin Powell
57 How I approach designing a website - my thought process
How I approach designing a website - my thought process
Kevin Powell
58 Build a website with Bootstrap 4 - Part 1: The setup
Build a website with Bootstrap 4 - Part 1: The setup
Kevin Powell
59 Build a website with Bootstrap 4 - Introduction
Build a website with Bootstrap 4 - Introduction
Kevin Powell
60 Build a website with Bootstrap 4 - Part 2:  Customizing Variables
Build a website with Bootstrap 4 - Part 2: Customizing Variables
Kevin Powell

The video teaches developers to adopt the modern CSS color syntax, using space-separated syntax with a forward slash for alpha values, and explores the benefits of using new color functions like OKLCH and LAB for wider color gamut and relative colors.

Key Takeaways
  1. Stop using the legacy color syntax
  2. Use space-separated syntax with a forward slash for alpha values
  3. Explore new color functions like OKLCH and LAB
  4. Use relative colors for more flexibility
💡 The new color syntax allows for wider color gamut and more flexibility with relative colors, making it a better choice for front-end development.

Related Reads

📰
I let an AI write 6 WebGL hero sections — here's the one-CSS-variable reskin trick, and the honest review count
Learn how to reskin WebGL hero sections using a one-CSS-variable trick and discover the author's honest review of AI-generated code
Dev.to · NeroTran
📰
Real-Time Rails Without Turbo: Modern Reactive UIs with Inertia and DexieCable
Learn how to build real-time Rails applications without Turbo using Inertia and DexieCable for modern reactive UIs
Dev.to · Stefan Buhrmester
📰
The Frontend Build Wars: Why Webpack’s Architecture Collapsed and How Rust Took Over
Learn how Webpack's architecture collapsed and how Rust is taking over in the frontend build wars, and why 86% of developers still rely on outdated tech
Medium · JavaScript
📰
Persisting User Data in a No-Backend HTML App (localStorage Patterns)
Learn how to persist user data in a no-backend HTML app using localStorage patterns
Dev.to · PromptMaster

Chapters (5)

Introduction
1:45 probably not worth refactoring
2:00 Why we need to get used to the space-separated syntax
2:50 Wider color gamuts with the new ones
3:50 Relative colors use the space-separated syntax
Up next
Best Free Loading Animations for Web Developers
Alamin
Watch →