Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In this hands-on course, James Williamson demonstrates the concepts that form the foundation of Cascading Style Sheets (CSS), including styling text, adding margins and padding, and controlling how images display. The course also explores the tools needed to work with CSS, the differences between embedded and external styles, how to use selectors to target elements, and what to do when styles conflict.
HSL stands for hue, saturation and lightness and represents a fairly recent addition to CSS in terms of being another option for defining color. Now HSL is defined as a mixture of a color's hue, saturation and lightness value. Sometimes it's referred to as brightness. A color's hue is represented as an angle on the color wheel as such as the color wheel you're seeing here, with ranges from 0 to 360. Now red is at 0 and 360, it's kind of at both if them. Green is at 120, blue is at 240 and all those other colors such as a yellow, orange and violet are found between those values as you just sort of go around that color wheel.
Saturation represents the amount of color, how much color a particular shade has. With 100% being fully saturated and 0% being grayscale.Lightness is how bright or dark the color is, and just like saturation it's defined using a percentage with 100% being very bright such as white and 0% being black. So now that we sort of know how HSL works, let's go take a look at the syntax and experiment with using it. And to do that, we are going to work on the hsl.htm file.
You can find this one on the 06_04 directory. It's very much like the last two files that we worked on here. We have our HSL colors headline and then a paragraph below it. We are going to be setting HSL values for the background, and for the foreground color. In my opinion, HSL is a little bit more intuitive, if you are just trying to mix a color on the fly. Remember the values for the color wheel that we talked about, reds are in the 0-360 range and little bit on either side of that. Your green is at 120, blue is at 240 and those values kind of in the middle there, so if you know which are going for, it's pretty easy to start of with a hue and see if you getting it right and then adding or subtracting from the values, to get the color that you are looking for.
Let's take a look at how that will work and how the syntax works. So I am going to go into the background here, and I am going to type in hsl and then once again, you just have open and close parenthesis. So the syntax is very much like RGB. What differs from RGB however are the three values that you pass in terms of how those are formatted. The first value that you pass in is the position on the color wheel that you want to start at, the hue. And this is represented just by a single number, so whatever you want that number to be. So let's say we want to start at a blue. Remember our color value is of 240.
So I am just going to type 240 in. Now your separate these values with commas just like you do in the RGB, color notation, and then we follow these with two percentage values. The first percentage value is saturation, the second percentage value is brightness. Let's say that we crank the saturation way up. So I do 100%. And then I can experiment a little bit of brightness. Let's keep this color pretty bright for the background originally. Let's say, I do something like 85%, okay. So if I save this and preview this in one of my browsers, there's our blue color very saturated, very bright.
And if I go back in to my file, I can just move this hue around a little bit. Let's say I go to 150 so if I save this, and preview it. You notice, I am moving in towards the greens, if I go below 120 maybe somewhere around 60, if I save that and test it I get into my yellows, if I get down into say the 15 or so that should be in my reds. This indeed you can see a sort of an orangish red color or pinkish color if you will, and if I go the opposite way, let's say I go to say 280, if I save this and test it.
You see I am going more towards the purple. So once you understand where the position on the color wheel is for these, it becomes a little bit more intuitive. All right, so what if you want to do white and black. Or let's say I want to have a black background and a white foreground. If you want to do that, the position on the hue doesn't really matter. What does matter are your saturation and your brightness. So if I take the saturation down to zero and zero and then do another hsl value here for color so let's just say hsl and then again it's not going to matter here what I do so let's say, I do something like ((20, 100%, 100%);).
So if I save this, and preview it, I get exactly what I was looking for, I get black and white. So I want you to play around with these colors a little bit. I am going to settle on a background color of 25 and the white space between the commas doesn't matter, just helps me read it, 40% for saturation and 20% for brightness, and then for the foreground color, I am going to use a hue of 20 a saturation of 100% and a brightness value of 100%. So can you guess the color that these are going to be using? If I save this, preview that in my browser, I get sort of a dark brown color for the background and sort of a bright color for the foreground.
So play around these values a little bit. See if you can start mixing colors together intuitively like, hey, I want a green, I want a bright green, I want a dark green, I want a de-saturated green, or I want a bright purple and you start working those and see if they sort to make sense to you in terms of mixing these colors together after a little while. It may take a little bit of getting used to, but I think it's a lot more natural way of defining colors once you get the hang of it. And once you know the relative values of the color on the hue color wheel that we're talking about, then mixing the exact value you want, is usually pretty intuitive.
There are currently no FAQs about CSS: Core Concepts.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.