New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

CSS Fundamentals
Illustration by

Color


From:

CSS Fundamentals

with James Williamson

Video: Color

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.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
CSS Fundamentals
3h 14m Beginner Sep 26, 2011 Updated Dec 13, 2011

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.

Topics include:
  • Understanding basic selector types
  • Integrating CSS with HTML
  • Examining browser rendering differences
  • Exploring CSS specifications
  • Checking browser support
  • Understanding the box model
  • Adjusting margins and padding
  • Positioning elements
  • Exploring basic layout concepts
  • Understanding media queries
  • Introducing CSS3
  • Using CSS Reset
Subjects:
Web Web Foundations
Software:
CSS
Author:
James Williamson

Color

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.


Expand all | Collapse all
please wait ...
Q: This course was updated on 12/13/2011. Can you tell me what has changed?
A: One movie called "Who is this course for?" was added to provide information on what you can expect to get from the course, depending on your level of familiarity with CSS.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS Fundamentals.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.