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

CSS Web Site Design

Defining color in CSS


From:

CSS Web Site Design

with Eric Meyer

Video: Defining color in CSS

In this video we're going to talk about the five ways to define color in CSS. The first one, you've already seen, or at least if you've watched the preview video, that's keywords, things like black, or White, or teal, or orange, just very civil names describe the color that they are creating. There's a limited list of those, which we'll see in just a moment. We also have a Hex, or hexadecimal, which there's an example here of CC3300 and then the short hexadecimal version. You can show things down basically, under certain circumstances, and we also have our RGB Decimal notation.
Expand all | Collapse all
  1. 14m 34s
    1. Welcome
      28s
    2. What is CSS?
      5m 34s
    3. Design tour
      2m 38s
    4. Using the exercise files
      1m 20s
    5. Installing the Web Developer toolbar
      4m 34s
  2. 25m 56s
    1. XHTML essentials
      3m 55s
    2. CSS essentials
      5m 17s
    3. Embedded style sheets
      2m 20s
    4. Linking a style sheet
      2m 19s
    5. Linking to multiple style sheets
      2m 20s
    6. Using linked and embedded style sheets together
      4m 21s
    7. Using imported style sheets
      5m 24s
  3. 57m 48s
    1. ID selector essentials
      6m 38s
    2. Class selector essentials
      4m 9s
    3. Best practices for classes
      4m 52s
    4. Grouped selection
      4m 2s
    5. Descendant selectors
      6m 44s
    6. The sources of style
      6m 38s
    7. Specificity
      8m 21s
    8. Making things important
      4m 32s
    9. Inheritance essentials
      5m 12s
    10. Making things really unstyled
      4m 2s
    11. User style sheets
      2m 38s
  4. 39m 3s
    1. Box model essentials
      7m 35s
    2. Simple floating
      5m 3s
    3. Using float for layout
      5m 5s
    4. Fixing column drop
      5m 35s
    5. Clearing essentials
      4m 20s
    6. Float containment
      6m 35s
    7. Creating a navbar from a list
      4m 50s
  5. 38m 3s
    1. Coloring text
      4m 13s
    2. Defining color in CSS
      8m 12s
    3. Coloring backgrounds
      6m 35s
    4. Applying background images
      4m 19s
    5. Manipulating the direction of background images
      2m 52s
    6. Positioning backgrounds
      7m 23s
    7. Background shorthand
      4m 29s
  6. 58m 28s
    1. Altering line height
      7m 32s
    2. Font style and weight
      5m 45s
    3. Sizing fonts
      9m 59s
    4. Using font families
      10m 38s
    5. Font shorthand
      6m 5s
    6. Justifying text
      4m 56s
    7. Vertically aligning text
      4m 22s
    8. Transforming text
      3m 49s
    9. Text decoration
      5m 22s
  7. 44m 40s
    1. Margin essentials
      14m 21s
    2. Adding borders
      6m 52s
    3. Padding
      9m 17s
    4. Using negative margins
      7m 19s
    5. Margin collapsing
      6m 51s
  8. 20m 38s
    1. Styling tables and captions
      5m 23s
    2. Styling table cells
      6m 30s
    3. Styling a column with classes
      4m 51s
    4. Styling links inside table cells
      3m 54s
  9. 30m 40s
    1. Styling for specific mediums
      4m 3s
    2. Creating a print style sheet
      6m 35s
    3. Hiding layout for print
      4m 11s
    4. Styling for print
      6m 34s
    5. Complex styling for print
      4m 37s
    6. Creating a footer
      4m 40s
  10. 37m 23s
    1. Getting started
      1m 11s
    2. Setting global styles
      4m 4s
    3. Defining masthead and navbar colors
      3m 27s
    4. Layout of the navlink bar
      3m 38s
    5. Using columns
      4m 49s
    6. Setting content styles
      1m 53s
    7. Creating the sidebar boxes
      5m 42s
    8. Creating the sidebar form
      3m 23s
    9. Completing the sidebar
      3m 29s
    10. Making a table
      3m 12s
    11. Creating a footer
      2m 35s
  11. 1m 28s
    1. Goodbye
      1m 28s

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 Web Site Design
6h 8m Intermediate Sep 12, 2006

Viewers: in countries Watching now:

CSS gives Web designers control over the appearance of their web sites by separating the visual presentation from the content. It lets them easily make minor changes to a site or perform a complete overhaul of the design. In CSS Web Site Design, instructor and leading industry expert Eric Meyer reviews the essentials of CSS, including selectors, the cascade, and inheritance. The training also covers how to build effective navigation, how to lay out pages, and how to work with typography, colors, backgrounds, and white space. Using a project-based approach, Eric walks through the process of creating a Web page, while teaching the essentials of CSS along the way. By the end of the training, viewers will have the tools to master professional site design. Exercise files accompany the training videos.

Subjects:
Web Web Design
Software:
CSS
Author:
Eric Meyer

Defining color in CSS

In this video we're going to talk about the five ways to define color in CSS. The first one, you've already seen, or at least if you've watched the preview video, that's keywords, things like black, or White, or teal, or orange, just very civil names describe the color that they are creating. There's a limited list of those, which we'll see in just a moment. We also have a Hex, or hexadecimal, which there's an example here of CC3300 and then the short hexadecimal version. You can show things down basically, under certain circumstances, and we also have our RGB Decimal notation.

For RGB values, you have the RGB with parentheses and inside of these parentheses you put the actual color that you want, in this case the decimal 204, 51, 0, or if you're going to use percentages, use something like 80%, 20%, 0%. Let's look at the keywords for a moment, there's a list of 17 keywords in CSS 2.1. In previous to CSS 2.1 there was actually a list of 16, but 2.1 added orange. So, sometimes we refer to CSS 2.1 as CSS, now with orange.

You can see here in this image that we took from the CSS 2.1 specification, these are the 17 named colors and their hexadecimal equivalents. Any browser that claims to be CSS conformant, has to be able to deal with these color names. Now, as you can see, these have hexadecimal equivalents, for example, red is ff0000, which basically means all the red you can give me and no green and no blue. White all ffffff, black all zeros.

The keywords are great if you just need one of the 17 colors and have no need for any more precise color then that, but you probably will need more precise color than that, as an example something that you might pick out of a color picker, like the one we see here from Adobe Photoshop. You can see right near the bottom of the dialog box, sort of to the right and center, there's a hexadecimal value right there, CC3300. That describes this particular color that's showing up in the preview box and right above that hexadecimal value, there's an RGB of 204, 51 and 0. Those are decimal RGB numbers.

So this particular shade of orange red CC3300, or 204, 51, 0, those are two different ways of expressing exactly the same color. Now, the other stuff there, you see the HSB, the Lab, HSB, the Lab, the CMYK. Those are the things that Photoshop allows you to do. You can't specify CSS colors using HSB, Lab, or CMYK notation, at least not yet. Maybe one day, but not right now. So let's go back to our list of keywords and there's our CC3300. In hexadecimal notation, each pair of digits describes the given color level. So, the first two digits, CC, that's two-digit hexadecimal number that describes how much red there's going to be and that's on a scale of 002ff, the hexadecimal being in the counting system that goes from zero to f and then starts over. So, the 33, is that level of green and then 00 is that level of blue, which would be none. So, in hexadecimal all white is all Fs and all black is all zeros.

CSS offers a short hexadecimal notation, where if you have a value that consists of two repeating pairs, like CC3300, you can short it down to just C30. Now, if we had CA3701, there's no way to take it down to the short hexadecimal notation, only if you have these explosive pairs, because when a browser sees C30, it says, oh ok, I have to expend this to CC3300. Now, is one better than the other to use.

Only if you like one better than the other. From a browser point of view, from my results point of view, these are functionally equivalent. C30 would give you exactly the same color that CC3300 does. So it really comes down to which one you prefer. You would rather have colors written out even when there are working in pairs. If you want them in the six digit notation, then that's fine, do that. If you like to compress it down to the shorter Hex, then go for it. Now, I said that the hexadecimal pairs go in the region 00 to FF. That's equivalent to the decimal range zero to 255, which is why the RGB decimal notation uses that range. White in RGB decimal is 255, 255, 255, black is 0, 0, 0.

So the equivalent of CC3300 is 204, 51, 0, just like we saw on our Photoshop color picker, CC3300, 24, 52, 0. Hexadecimal value CC is exactly equivalent to the decimal value 204. 33 in hexadecimal is 51 in decimal. So that's where RGB decimal come from, it's a base 10 decimal way of representing hexadecimal values, because not everyone can comfortably think in hexadecimal. Strange but true, so RGB decimal is there to make things a little easier and easier still is RGB percent, which in equivalence to our RGB 204, 51, 0 is an RGB of 80%, 20%, 0%.

RGB percentages go with a range as you might expect, 0% to 100%. White is all 100%, black is 0%. as we can see here. So how to get from RGB decimal to RGB percentage, is to divide each of the decimal values by 255. So our 204, 51, 0, 204 divided by 255 is 0.8 which is 80%, 51 divided by 255 is 0.2, that's 20% and zero divided by 255 of course is zero or 0%.

There're many people who find it much easier to think in terms of color percentages than they do in terms of decimal values on a rage, 0 to 255 or hexadecimal on a range 00 to FF. The drawback is that because of the way browsers are, percentages are a little bit courser, you should be in theory able to use the decimal fractions with the RGB percent, things like 66.67% and 42.5%, but browsers don't always handle that very well. Some of them will round down those fractions, so 66.67% becomes 66%. There are others that do or may in the future, round to the nearest whole number so the 66.67% will become 67%. So you get these slight differences in colors possibly between browsers if you use percentage fractions. So, if you prefer to use percentages, that's great.

By all means, do so. If you prefer to use the RGB decimal because they are a little bit more precise instead of basically a hundred points from 0-100, you have 255 points, from zero to 255. You can do that, or hexadecimal. Whatever you like. In a lot of cases, honestly, you're probably going to pick a color with a color picker or on a color wheel of some kind, once you find the color values that you want, you can get them out of your program if you're using Photoshop or if your sampling colors off of images, whatever it is you're doing, your tool will tell you, and probably in one of several ways what those color values are, you can probably get a six digit hexadecimal value out of it, or RGB 's from zero to 255 or even percentages.

So, you know, you can make some up in your style sheet, however you want to do them. There's no one that's objectively better than another. It's really just what makes you the most comfortable and as I say what your tools yield for you. If you use a Photoshop color picker, and it's got that little six digit Hex box right at the bottom, you can just select it and copy it and paste it in your style sheet and there you go. But, however you do it, not only can you apply these colors to text as we saw in a previous video, but also to backgrounds of elements as we'll see in the next video.

There are currently no FAQs about CSS Web Site Design.

Share a link to this course
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.

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 Web Site Design.

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
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



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.

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