02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Understanding how colors work in CSS

In the last lecture we spent a lot of time coloring the backgrounds of elements. In this lecture we turn our attention to colors and how they work in CSS. In the process, we will learn how to change the color of text in CSS, how hexadecimal values work and what is RGB.

Video Transcript

00:00Colors, you can't live without them.
00:03CSS is all about color manipulation.
00:06There's quite a few ways of dealing with colors.
00:08This lecture is gonna be about the colors
00:11that are very standard.
00:12You could use them throughout any application,
00:14really, on the modern web.
00:17We're gonna talk about color theory a bit,
00:18about the structure of color constructs.
00:22So by the end of this lecture,
00:23you will know how to define and manipulate colors
00:26using CSS.
00:27So let's jump right into it.
00:30Although this lecture is dedicated to color,
00:34really we're dedicating it
00:36to all the different types of color.
00:39So although we're gonna take a look and just take a gander,
00:41and I wanna go ahead and make sure
00:43that all the different text in my application will be white.
00:47Now, there's many ways for me to do that,
00:49and I wanna go over the different ways
00:51because it's so important now that you're doing CSS
00:54that you know how color systems work
00:56and how to work with colors in general.
00:58So I'm gonna stick around into my body
01:01and let me just make sure that I have your word route
01:02so we could see things more clearly.
01:05And I'm gonna go ahead and just add, right,
01:07let me just put it even before our background
01:08or let's skip down inside of our body.
01:11I just want everything, every font,
01:13every anything to have a specific color.
01:16Now to do that, I just set the color property,
01:19which will basically color all the different fonts,
01:22and then I could go ahead and define the color
01:24that I want it to be.
01:25And again, we were talking about the hexadecimal values,
01:29and they're so important,
01:30and you really need to understand how they work.
01:33You don't need to memorize the colors and how they work,
01:35but what you do need to remember is that there's red,
01:38there's green, there's blue channels.
01:41There's basically three channels for our colors.
01:43The first channel is two characters,
01:46the second channel two, and the last is two.
01:49The first channel represents red,
01:50the second green, and the last blue.
01:53RGB, just, it's something you've probably heard of before.
01:57The values, the range of values that are possible
02:01are any range between zero, zero, all the way to FF.
02:05When we said the characters that represent these numbers,
02:09I'm just gonna put that as a comment,
02:11the characters that represent these colors
02:13are basically from the character O, zero,
02:16then one, two, three, four, five, six, seven, eight,
02:19nine, A, B, C, D, E, F,
02:24and all these characters together combine,
02:26and create 15 characters.
02:28I have here nine, 10, 11, 12, 13, 14, 15,
02:31and the word hexademasle is basically 15.
02:34There's a lot of different numbering systems,
02:36although you're probably more familiar and more comfortable
02:39with number systems that start from zero and end at nine,
02:42which is our regular counting system,
02:46but this is a counting system that enables us
02:48to condense things and write a lot of different values.
02:51So really, in this case, just for the sake of clarity,
02:55if I have here the value of O, zero, F,
03:00what I really have is the value of zero times 15
03:05plus 15, which would basically account to 15.
03:11Now, on the other hand, and I'm just gonna go ahead here,
03:14and just for the sake of,
03:15because it's so important that you just understand
03:18how it works, you don't need to memorize it,
03:20and please don't.
03:21Don't try to memorize, you just don't need to,
03:23but to understand how it works, it is incredibly critical.
03:26All right, so for example, if I would set it to be A5,
03:29for example, what is the value A5
03:31if I would wanna translate it?
03:33The value A is actually 10,
03:36so that would be 10 times 15 plus five,
03:42so that would account to basically 155,
03:46so the value A5 really represents 155.
03:50Now, notice how wonderful this is
03:52because it enables you to create a large amount
03:55of color combinations.
03:57Now, FF is basically 15 times 15 plus 15,
04:04which would equal to 255,
04:08and that's really how this system
04:10basically works in a nutshell.
04:14That's it really, that is it in a nutshell,
04:16so FF is basically 255.
04:20Now, so whenever I'm setting here a value,
04:22literally what I'm saying is how much color
04:24do I want to have in this channel?
04:26Now, in this case, I really wanna create the white color.
04:29Now, if I wanted to create a black color,
04:31I would say no color for red.
04:34Let me just also make sure that
04:35we're gonna save this on the side here
04:37so you could then refer back to it whenever you want to.
04:40So I'm just gonna go ahead here and just break a line,
04:43and I'll just put this right here
04:44so you could have it there.
04:45So when we're talking about the red channel,
04:47what value, if I wanted it to be black,
04:48I'll just set it to be zero on the two characters
04:52that represent that red channel.
04:54For the green channel, I would set it to be zero as well.
04:57For the blue channel, I would represent it to be zero as well,
05:00and in that case, I would get that default value,
05:03which is the black that we've already seen before.
05:06Contrary to that, if I wanted to create a white color,
05:09I would go ahead and just say,
05:10hey, I want to get the full color gamut.
05:12By the way, it doesn't matter
05:13if you put lowercase or highercase,
05:15and I literally, okay, so I have your complete color
05:19for red, complete color for green, complete color for blue,
05:21and this color combination will create
05:24that beautiful white color that we want
05:26for our application.
05:28Now, again, that's really no need for, again,
05:32that is really just how hexademesal values work in general,
05:36and that is true to any other place where you have color.
05:38Any place that accepts color in CSS
05:41accepts this type of color option.
05:44Now, there's a few different types of color options
05:46that CSS could accept,
05:48and if you're more comfortable with other types,
05:50then let's go cover them.
05:52Now, the secondary option,
05:54and I'm just gonna go ahead here and just break this
05:57and just put this into context,
06:00the next item possible is literally
06:02just writing the value, white.
06:04Now, not every single color would work,
06:06but definitely all the different colors
06:08that are registered in CSS, most common colors,
06:12so white, blue, red, other commonly named colors,
06:17and if I go ahead and do that and click on refresh,
06:19we'll see that we'll get the same value.
06:20So if I wanted a complete, accurate name
06:23that has a name to it, then I could just write here
06:26white if I wanted to.
06:28So I'm gonna go ahead here and just cut that out
06:30and just put that up there
06:31so you have that as an option as well.
06:34Another coloring system option is called the RGB mode,
06:38which is basically the same thing
06:39as what we've done so far.
06:41We're sending in the channels separately,
06:43but instead of sending in a hexadecimal value,
06:47I'm sending it with a comma,
06:49basically setting up to 255 comma 255 comma 255
06:55for red, green, and blue.
06:58So in this case, I'm gonna be setting again
06:59that white color that we were talking about previously.
07:03So if I go ahead here and click on refresh,
07:04we'll see again, I'm getting a white color,
07:07and I could choose which color combination
07:09of all these three formats,
07:11but obviously this format is much shorter
07:14because that means you have less typing,
07:16and if you have less typing,
07:18well, that means you're gonna have less file size,
07:20and if you have less file size,
07:21that's gonna cut down on the amount of time
07:23it takes for your file to be served,
07:25which is why we use hexadecimal values,
07:27but if this is more convenient to you,
07:30then you could use them.
07:31Now in another note before we really get close
07:35to wrapping up this topic is again,
07:36make sure that you install the color picker on Firefox
07:40and use Firefox,
07:40and notice that when you select a color,
07:43you could see also all those RGB values of their setup.
07:47Not only that, if I go ahead here
07:49and I just select one of those colors right here,
07:52I could literally press on it again,
07:54and if you just look at here,
07:56although there's a little bit of a,
07:59kind of like a overshadow here
08:01because it's a little bit out of the screen,
08:03you'll see that I have your,
08:04I could copy the specific values based on the type
08:06that I want,
08:07although the default will be our hexadecimal value.
08:11So don't worry that it's out of the screen,
08:12you could just open up yourself
08:13and see it as you use the color picker.
08:16Now I wanna talk about another color system,
08:19and this color system is really represented here
08:22that we could literally see it here,
08:24although you probably don't see it fully,
08:25it's the HSL.
08:28Now the HSL, and I'm just gonna grab it,
08:30the HSL color system,
08:32it works a little bit differently
08:33than everything else we've seen so far.
08:36The way it works is really,
08:38it's about hue, saturation, and lightness,
08:44and we're gonna look into that in the next lecture
08:46because we can't complete everything in one lecture.
08:49So in the next lecture, we're gonna stay in color,
08:51and we're gonna take a deeper look at what this is.
08:54Now, I suggest you encourage you,
08:56try to figure out on your own even before we see it,
08:58and in the next lecture,
08:59we're gonna look into different various options
09:02that you could work with this type of system.
09:04It's literally just another way to represent colors,
09:07but it's not gonna be the last color we talk about
09:10because we're also gonna talk about
09:11how to create transparent assets in CSS,
09:14and that's gonna be the next topic
09:16as we continue talking about colors in the next lecture.
09:19So see you in the next lecture.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!