CHAPTER 6

CSS Colors

CSS colors are used to control the color of text, backgrounds, borders and other elements.

01. What is CSS Colors?

CSS supports named colors.
Colors can also be written using hexadecimal values.
RGB and RGBA can be used to define colors.
HSL and HSLA are also supported color formats.

02. Syntax

color: red; color: #2563eb; color: rgb(37, 99, 235); color: rgba(37, 99, 235, 0.5); color: hsl(217, 91%, 60%);

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>

<head>

    <style>

        .name {
            color: blue;
        }

        .hex {
            color: #2563eb;
        }

        .rgb {
            color: rgb(220, 38, 38);
        }

        .rgba {
            color: rgba(16, 185, 129, 0.7);
        }

    </style>

</head>

<body>

    <h2 class="name">
        Named Color
    </h2>

    <h2 class="hex">
        Hexadecimal Color
    </h2>

    <h2 class="rgb">
        RGB Color
    </h2>

    <h2 class="rgba">
        RGBA Color
    </h2>

</body>

</html>

04. Important Points

✓ Hexadecimal colors commonly use six characters such as #2563eb.
✓ RGB represents red, green and blue values.
✓ RGBA adds an alpha value for transparency.
✓ Choose colors with sufficient contrast for readable interfaces.

05. Common Mistakes

⚠ Using invalid hexadecimal values.
⚠ Using RGB values outside the valid range.
⚠ Choosing colors that make text difficult to read.

06. Real World Use

Color systems are used to create brand identities, buttons, alerts, backgrounds and visual hierarchy.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Color Palette

Create four boxes and style each box using a different CSS color format.