Learn an easy method to pick UI colors using HSL for neutral palettes, dark/light modes, and practical CSS implementation.
Key Takeaways
- HSL is the preferred color format for creating intuitive and harmonious UI color palettes.
- Neutral color palettes rely on zero saturation and varying lightness to define backgrounds and text.
- Dark and light modes can be created by inverting lightness values and adjusting for natural light perception.
- CSS variables and simple JavaScript enable easy theme toggling and color management.
- Adding borders, gradients, highlights, and shadows improves UI depth and user experience.
What the video covers
- UI colors are simpler than they seem; focus on neutral backgrounds, primary brand colors, and semantic colors for states.
- Use HSL color format instead of HEX or RGB to intuitively create harmonious shades by adjusting lightness.
- Create neutral palettes by setting hue and saturation to zero and varying lightness for backgrounds and text.
- Design both dark and light modes by flipping lightness values and adjusting colors for visual logic and contrast.
- Implement colors in CSS with variables, toggling themes via JavaScript or media queries for user preference.
- Enhance UI with borders, gradients, highlights, and shadows to add depth and visual interest without overwhelming.
- Use alpha transparency in shadows and combine multiple shadows for realistic effects.
- Explore hue and saturation adjustments to customize the look from vibrant to neutral using a custom tool.
- Test and tweak colors in both modes, especially primary and secondary colors used for buttons and interactions.
- Sponsored by Brilliant, a learning app promoting hands-on problem solving for better understanding of concepts.
Full Transcript — Download SRT & Markdown
Speaker A
Colors are one of those things where the more you learn, the more you realize how much you didn't know before.
Speaker A
And it gets complicated real fast, but for UI stuff, you don't need to become a color scientist.
Speaker A
In my experience, colors are honestly the easiest part of the UI.
Speaker A
The tricky bit is knowing when to stop playing and just pick something that works.
Speaker A
Here's what actually works: neutral colors for background, text, borders, and a lot of other elements.
Speaker A
The brand or primary color for main actions and to add a bit of character.
Speaker A
And finally, maybe some semantic colors to communicate different states.
Speaker A
These are all the colors you'll ever need to design apps and UIs.
Speaker A
When I say colors, what I actually mean is shades, you will see this everywhere on a UI.
Speaker A
Like when you hover over a button or a gradient background.
Speaker A
To create shades, you need to pick the right color format.
Speaker A
Most people are familiar with HEX and RGB color values, but they are the worst when it comes to creating a color palette.
Speaker A
Like these three shades of gray we have for our background colors.
Speaker A
They look very similar visually, but the code doesn't.
Speaker A
Now compare that with a more intuitive color format, and the code actually makes sense.
Speaker A
You have hue or the actual color on the color wheel that goes from 0 to 360.
Speaker A
Then the saturation, which goes from 0 to 100, controls the intensity of that color.
Speaker A
In our case, we have set it to zero.
Speaker A
That means no matter what color you choose for the hue, it's always going to be neutral.
Speaker A
And finally, we use the lightness value to create a bunch of shades.
Speaker A
Simple and easy math to create a harmonic palette without any guesswork.
Speaker A
Now that we've learned how to play with colors, let's create the most prominent colors of a UI.
Speaker A
Background and text colors.
Speaker A
I'll start with dark mode because let's be honest, it slaps.
Speaker A
But yes, we will cover light mode as well.
Speaker A
Saturation can stay at 0% because we are creating a neutral palette.
Speaker A
Without saturation, hue doesn't matter anyway.
Speaker A
I will cover hue and some other important things later in the video.
Speaker A
With hue and saturation both set to zero, we will start with 0% lightness for our base color.
Speaker A
Then 5% for the next shade that can be used for cards and other surface elements.
Speaker A
And finally 10% to highlight the most important or raised elements.
Speaker A
The lighter elements appear on top and feel closer to the user.
Speaker A
So obviously, only use them for important stuff.
Speaker A
Same thing with text.
Speaker A
Keep a sharper and high contrast color for headings and important elements, and use a slightly muted shade for the rest.
Speaker A
Still legible, just not in your face all the time.
Speaker A
That's why we don't use 100% lightness for the headings.
Speaker A
It would look too harsh on the eyes.
Speaker A
Speaking of harsh, let's flip these colors for light mode.
Speaker A
Start by subtracting the lightness value by 100.
Speaker A
That'll give you a good starting point.
Speaker A
Then we'll use our eyes and some common sense to adjust the values manually.
Speaker A
For example, why does the top element have the darkest color?
Speaker A
Light usually comes from the top, so it should be the lightest, and the base color should be the darkest.
Speaker A
That's why I name my background colors as BG dark or BG light.
Speaker A
So BG dark will be the darkest and BG light will be the lightest shade.
Speaker A
Whether it's dark or light mode.
Speaker A
But we can't do that with text colors.
Speaker A
So use names that make sense for both cases.
Speaker A
If you're into this kind of logic meets visual thinking, you'll love Brilliant.
Speaker A
The sponsor of this video.
Speaker A
Brilliant is a learning app designed to be uniquely effective.
Speaker A
Each lesson is filled with hands-on problem solving that lets you play with concepts.
Speaker A
A method proven to be six times more effective than watching lecture videos.
Speaker A
Plus, all content on Brilliant is crafted by an award-winning team of teachers and professionals from top-tier organizations.
Speaker A
So you can become a better thinker and problem solver with every lesson.
Speaker A
Whether you are learning to code, build formulas, design electrical circuits, or explore cutting-edge topics like AI to understand how these large language models actually work.
Speaker A
Brilliant literally has everything.
Speaker A
And you can try it all for free for a full 30 days.
Speaker A
Just visit brilliant.org/sajid or click the link in the description.
Speaker A
Plus, you'll get 20% off an annual premium subscription.
Speaker A
So we have our background and text colors.
Speaker A
Before we move forward, let's quickly recap how we got here.
Speaker A
We picked the HSL color format, so the colors actually make sense in code.
Speaker A
We kept hue and saturation at zero because we want a neutral color palette.
Speaker A
And without any saturation, hue doesn't matter anyway.
Speaker A
Then we just played with the lightness value to create three shades for the background and two shades for text colors.
Speaker A
And finally, we flipped these colors for light mode by subtracting the lightness value from 100.
Speaker A
That gave us a good starting point.
Speaker A
But BG dark and BG light didn't make any sense.
Speaker A
So we switched them out to get our final colors.
Speaker A
And that's all we've done so far.
Speaker A
All right, let's shift gears and write some CSS.
Speaker A
First of all, set your colors like this.
Speaker A
Your default theme goes in the root, and then the other theme can go in the body selector like this.
Speaker A
Then, one line of JavaScript to toggle it back and forth.
Speaker A
Or just wrap your light mode in this media query to automatically adapt to user's preferred theme.
Speaker A
There are many ways to do this, and your implementation will depend on your framework.
Speaker A
Or how much control you want to give the user.
Speaker A
But the main task is defining your colors.
Speaker A
The rest can be handled by the agent.
Speaker A
For this video, I'm going to stick with this simple logic.
Speaker A
Define my color variables like this, and then use those variables to set the background and text colors.
Speaker A
At this point, our UI looks too boring.
Speaker A
So to fix that, we're going to use four more properties.
Speaker A
As always, let's start with dark mode.
Speaker A
The border should be clearly visible, but not too distracting.
Speaker A
Then, create a simple gradient using our background colors.
Speaker A
If it feels too distracting, we can tweak it a bit and reveal the full gradient on hover.
Speaker A
This way, it looks shiny on top, like the light is coming from above.
Speaker A
To really sell this effect, we can use a lighter color for the top border.
Speaker A
And I'm calling it, you guessed it, highlight.
Speaker A
Now let's see how this looks in light mode.
Speaker A
Since we haven't defined our gradients for light mode yet, it's still showing the dark mode version.
Speaker A
So let's just copy the border, gradient, and highlight into light mode first.
Speaker A
This is nice, but we can make it 10 times better.
Speaker A
First of all, the highlight in light mode doesn't look like a highlight, but a plain border.
Speaker A
So let's bump the lightness all the way up.
Speaker A
Now the border doesn't make any sense and looks ugly as hell.
Speaker A
To solve this issue, I'm going to create a new variable that can be applied directly as the border.
Speaker A
Then, we'll change the border color to match the background color in light mode, so it blends into the card.
Speaker A
And finally, let's add a nice shadow to create some depth.
Speaker A
Because where there's light, there's a shadow.
Speaker A
Shadows need some transparency, so you'll need to use an alpha value that goes from 0 to 1.
Speaker A
Always mix a darker and shorter shadow with a lighter and longer one to achieve a more realistic effect.
Speaker A
But did you notice, we've come this far without even touching hue or saturation?
Speaker A
So let's see what hue and saturation can do for your designs.
Speaker A
I've made a tool that lets you do just that in real time.
Speaker A
I've already set the right contrast, gradient, highlight, and shadows.
Speaker A
All you need to do is play with hue and saturation.
Speaker A
Want a cool and vibrant look or something warm and neutral?
Speaker A
This lets you try everything and find the perfect balance for your project.
Speaker A
Then just flip this switch and see if the light mode needs any tweaking.
Speaker A
Make sure to check all the colors, especially your primary and secondary ones, since they're mainly used for buttons and hover states.
Speaker A
Once you're happy with the results, just click this button to copy the colors.
Speaker A
What the hell is OKLCH and why is it the default color format?
Speaker A
Forget the OK part for a second, just look at LCH.
Speaker A
L and H are lightness and hue, which you already know from HSL.
Speaker A
C stands for chroma, which is kind of like saturation.
Speaker A
But instead of going from 0 to 100, it goes from 0 to 0.4.
Speaker A
And for UI work, you rarely need more than 0.15 or 0.2.
Speaker A
As I said in the beginning, colors are one of those things where the more you learn.
Speaker A
The more you realize how much you didn't know.
Speaker A
And it gets complicated real fast.
Speaker A
Hue is the same as before, 0 to 360.
Speaker A
Chroma goes from 0 to 0.2, and lightness goes from 0 to 1.
Speaker A
Actually, LCH is a color format on its own.
Speaker A
OKLCH is the newer and better version of it.
Speaker A
With the V4 update, Tailwind has also switched to OKLCH as the default color format.
Speaker A
So let's compare these three color formats and see how they differ.
Speaker A
With HSL, the biggest issue is how it handles lightness.
Speaker A
The dark and light shades lose all saturation.
Speaker A
With LCH and OKLCH, the increments look way more natural.
Speaker A
By the way, I'll show you some more variations and leave it up to you to decide which one looks better.
Speaker A
Feel free to pause or take screenshots, since I'll be going through them quickly.
Speaker A
So what do you think?
Speaker A
You can still just copy the HSL code if you want.
Speaker A
The theme includes everything, both color formats for dark and light mode.
Speaker A
Just copy-paste the code into your CSS file and start designing.
Speaker A
I'll leave the link in the description, right below these beautiful buttons.
Topics:UI colorscolor paletteHSL color formatdark modelight modeCSS variablescolor theoryUI designcolor shadestheme toggling











