Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
This course contains a high-level overview of Cascading Style Sheets, while exploring the basic concepts, terminology, and tools of the language. Beginning with an exploration of CSS syntax, author James Williamson explains how CSS modifies text, borders, backgrounds, and color; demonstrates CSS and HTML integration; and contextualizes the current state of CSS. The course also tours some of the most popular CSS editors and frameworks and lists online tools and resources for further study. This course is for people who want a big-picture overview before taking hands-on courses.
Whenever I'm learning a new language or new forms of syntax, there always seems to be something that everyone just takes for granted that you already know. In the years that I've spent teaching CSS, it seems like no one ever really concentrates on how color works and how the syntax is used to define it. There are three primary properties that you'll use when defining color in CSS. Two of them, border-color and background-color, we've already discussed. The third property is the color property, and it's used to define the color for the content of an element.
Many people often refer to this as foreground color, and in terms of elements like paragraphs, headings, and lists, it refers to the color of the text. Whether you're defining color on borders, backgrounds, or element content, you have a number of options in terms of how you want to define in the color. First, you can choose from one of more than one hundred and fifty color keywords supported by CSS. In older versions of CSS, you were limited to the sixteen color keywords, but in CSS3 support has been added for the SVG 1.0 color keyword names, greatly expanding the range of available keywords.
These keywords mapped to a predetermined set of RGB values the browsers will use to display the color. In the place of keywords, you can also use hexadecimal notation to represent color values. Essentially, hexadecimal notation is another way of representing RGB color by using three hex pairs to represent the red, green, and blue values of a color. The easiest way to visualize hexadecimal notation is to examine this table. When you have a hex value like this one, you match up the first pair of values for red, the second pair of values for green, and the final pair of values for blue.
Now, I'm not going to lie to you and say that I can spout hexadecimal notation off the top of my head, but over time you'll memorize the ones that you use most frequently. You'll also want to become familiar with using shorthand hex values for web-safe colors. If the hex values are made up of pairs, you can shorten them to three characters instead of six. FFF would represent FFFFFF, or white, while 000 would represent 000000, or black.
Keep in mind that all three values need to be matching pairs, so FF33AB couldn't be represented using shorthand. If you don't want to use hexadecimal values, you can stick with using RGB color values. To use actual RGB values, you'll simply declare RGB for the color value and then pass either numeric values for the red, green, and blue values, or you can use percentages if you'd like. CSS3 introduces a new method of defining color as well, and that is the HSL model.
If you're familiar with Photoshop or other photo editing software, you've probably used HSL at least once or twice. It stands for Hue, Saturation, and Lightness, and gives us a more intuitive way of defining color. RGB is an additive mixture of red, green, and blue colors that range in values between 0-255. Now if all three of them are set to 255, you get white; if all the colors are removed or set to zero, you get black.
It can become very difficult to try to mix RGB colors without a color picker or some sort of other aid. Now HSL, on the other hand, is a mixture of a color's hue, saturation, and lightness. A color's hue is represented as an angle on a color wheel, with ranges from 0 to 360. Red is 360; green is 120; blue is 240; and other colors such as yellow, orange, and violet are found in between those values.
Saturation represents the amount of color, 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 as a percentage, with 100% being a bright white, 0% being black. Now, while this declaration is relatively new to CSS, it already enjoys widespread support among modern browsers. In addition to color, CSS also allows us to define transparency for elements, and it gives us a couple of different ways to do this.
Now first, we're able to use the opacity property. Opacity can be defined using a value from zero to one. So to make an element 50% transparent, for example, you'd use 0.5 for the value. Now the thing about opacity is that it defines the opacity for the entire element: borders, backgrounds, and all. In order to give you some additional flexibility when defining opacity, CSS3 introduced the concept of RGB and HSL alpha.
Essentially, you can add a fourth value to RGB and HSL definitions in the form of a range of 0-1. This allows you to have individual transparency settings for backgrounds, borders, and foreground colors. Like HSL itself, RGBA and HSLA enjoy a widespread support among modern browsers. I know this movie has probably been a little bit more technical in terms of the syntax and how deep we've dived into it than some of our other movies, but when learning, I think you'll find the color values are often given with little to no explanation as to what they mean, and I wanted to make sure that you have an understanding of why certain values are used and what they refer to when specifying the colors involved in your design.
Find answers to the most frequently asked questions about CSS Fundamentals.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
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.