Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Hexadecimal Colors

Hexadecimal colors (hex colors for short) are RGB colors written in a different way. They are the most common way to write colors on the web, and graphics programs offer them too, so you will see them everywhere.

A hex color starts with #, followed by three pairs of characters: the first pair is red, the second green and the third blue:

h1 {
	color: #ff0000;
}

Each pair is a number written in the hexadecimal system. The decimal system we use every day has ten digits (0 to 9). The hexadecimal system has sixteen: 0 to 9 and then the letters a to f, where a = 10, b = 11 and so on up to f = 15. In a two-digit hexadecimal number, the first digit counts sixteens: ff = 15 × 16 + 15 = 255, and 80 = 8 × 16 + 0 = 128. So two hexadecimal digits cover exactly the range from 0 to 255, just like one number in RGB.

That's why #ff0000 is the same color as rgb(255, 0, 0): red. Black is #000000 and white is #ffffff. It doesn't matter whether you write the letters in uppercase or lowercase.

When both characters of each pair are the same, there is a short form with three characters: #fff means #ffffff and #f00 means #ff0000.

Now let's color all the text on the page. We don't need one rule for paragraphs and another one for list items: color is inherited, so it's enough to set it on body. Every element inside gets the color, unless it has a color of its own. Our h2 headings and the main heading have their own colors, so they keep them.

Instructions

  1. 1

    In the rule for body, add the declaration color: #2a231b, a very dark brown.

Back

5/9

  1. 1. Named Colors
  2. 2. Quiz: Named Colors
  3. 3. Background Color
  4. 4. RGB Colors
  5. 5. Hexadecimal Colors
  6. 6. HSL Colors
  7. 7. Transparent Colors
  8. 8. Opacity
  9. 9. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.