LESSON 3.05

CSS Colors

Bring your designs to life with color

Explore the different ways to specify color in CSS, including named colors, hex codes, and RGB values, and start making your pages visually engaging.

💡 The Concept

CSS colors can be written in several different formats, giving you flexibility and precision when defining color values in your code. When adding colors to a website, you will most frequently use a hexadecimal value. But CSS gives you several ways to specify color. In this lesson we will cover named colors and hexadecimal (hex) color codes. Named colors are the easiest for practicing CSS, but in live web development you will usually use hexadecimal numbers. This lesson covers named colors and hex codes. RGBA colors, which add transparency control, are covered in the next lesson.

Method 1: CSS Color Names

The simplest way to add color is to use a named color, like “blue”, “pink” or “hotpink”. CSS recognizes 147 predefined color names that all modern browsers support.

This graphic shows all of the color names. Click the graphic to see all the colors in a larger font:

All of the CSS color names and their corresponding hex numbers.

Named colors are perfect for quick prototyping and experiments because they are easy to read and remember. However, 147 options is a limited palette when you are trying to match a specific brand color — that’s where hex comes in.

Method 2: Hexadecimal (Hex) Colors

Hexadecimal color codes are the workhorse of web design. A hex code is a six-character string preceded by a hash symbol (#). It represents a color by mixing red, green, and blue channels — each defined by a two-digit hex number ranging from 00 (none) to FF (maximum).

Mixing three channels in different proportions gives you access to over 16 million colors — far more than the 147 named options.

Shorthand Hex

When each pair of digits is identical, you can use a three-character shorthand:

/* These pairs are identical */
color: #FF6600;          color: #F60;
color: #000000;          color: #000;
color: #FFFFFF;          color: #FFF;

Where to Find Hex Codes

You will rarely memorize hex values — you just need to know where to look them up. This course has two tools built just for that. The Simple Hexadecimal Color Picker lets you pick any color and instantly get its hex code. The CSS Color Name Picker shows you all the named CSS colors in one place. Both are on your Tools of the Trade page — bookmark it if you have not already.

🎬 Video Demonstration

This video demonstrates how to find hex color values and apply them to your page:

Exercise: Try It Yourself

📌 Tools of the Trade: The Tools of the Trade page has a Hex Color Picker and a CSS Color Name Picker. Bookmark it now for quick color reference throughout the course.

Open JSFiddle.net and follow the steps below. For your colors, open the Hex Color Picker and choose your own — do not use the same colors shown in the screenshot!

Step 1. In the HTML panel, type:

<h1>Hello CSS!</h1>

Step 2. Go to the Hex Color Picker and choose a background color you like. In the CSS panel, add:

body {
  background-color: #your-hex-color;
}

Step 3. Go back to the Hex Color Picker and choose a color for your heading text. Add:

h1 {
  color: #your-hex-color;
}

Step 4. Click Run and see your result. Try swapping in different colors until you find a combination you like.

JSFiddle showing a background color on body and an h1 color.

Frequently Asked Questions

Why do developers usually use hex numbers instead of color names?

Hex codes give you precise control over color. There are only about 140 named CSS colors, but hex codes can represent over 16 million colors. Once you get used to them, hex codes are also faster to type and easier to copy from design tools like Figma or Photoshop. Most color pickers output hex codes by default, so they fit naturally into a developer’s workflow.

Why are they called hex numbers?

Hex is short for hexadecimal, which means base 16. Regular numbers are base 10, using digits 0–9. Hexadecimal uses 16 symbols: 0–9 and then A–F, where A equals 10, B equals 11, and so on up to F equals 15. A CSS color like #FF0000 is actually three two-digit hex numbers representing the amounts of red, green, and blue in the color.

What does the # symbol mean in a hex color?

The # is just a signal to the browser that what follows is a hexadecimal color value rather than a color name. Without it, the browser would not know how to interpret the number. Think of it like a label that says “hex color coming up.”

Can I use color names instead of hex codes?

Yes, and for simple colors like red, blue, or white, color names are perfectly fine. But with only about 140 named colors available, you will quickly run into situations where the color you want does not have a name. Hex codes give you access to the full spectrum, so most developers default to them.

Why does my hex color sometimes have only 3 digits, like #fff?

Three-digit hex codes are a shorthand. When both digits in each pair are the same, you can write just one. So #ffffff becomes #fff, #000000 becomes #000, and #ff0000 becomes #f00. The browser expands them automatically. You will see this shorthand used in a lot of CSS code in the wild.

How do I find the hex code for a color I see on another website?

The easiest way is to use Chrome Developer Tools. Right-click the element, choose Inspect, and find the color property in the Styles panel — clicking the color swatch opens a built-in color picker. You can also use the Hex Color Picker on the Tools of the Trade page to explore colors and grab their codes.

Are color names case-sensitive in CSS?

No. The browser accepts Red, red, RED, and even rEd — they all produce the same result. That said, lowercase is the standard convention in CSS, and sticking to it keeps your code consistent and easier to read.

Key Takeaways

Color is one of the first things visitors notice about a website. This lesson covered three ways to set color in CSS: named colors and hex codes. Next, you will learn about RGBA colors, which add a fourth value for controlling transparency. Transparent colors are great for overlays, backgrounds, and subtle design effects.

Google Ads

The costs of this website are partially offset by revenue from Google Ads.

Tools of the Trade

HTML/CSS Lessons