CHAPTER 48
CSS Colors Advanced
Learn modern CSS color formats including RGB, RGBA, HSL and HSLA.
01. What is CSS Colors Advanced?
CSS supports several ways to define colors.
RGB uses red, green and blue values.
RGBA adds an alpha channel for transparency.
HSL represents hue, saturation and lightness.
HSLA adds transparency to HSL.
02. Syntax
color: rgb(37, 99, 235);
color: rgba(37, 99, 235, 0.5);
color: hsl(217, 91%, 60%);
color: hsla(217, 91%, 60%, 0.5);
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.rgb {
color: rgb(37, 99, 235);
}
.rgba {
background: rgba(37, 99, 235, .15);
}
.hsl {
color: hsl(217, 91%, 60%);
}
</style>
</head>
<body>
<h2 class="rgb">
RGB Color
</h2>
<div class="rgba">
RGBA Background
</div>
<h2 class="hsl">
HSL Color
</h2>
</body>
</html>
04. Important Points
✓
RGB represents red, green and blue.
✓
RGBA includes transparency.
✓
HSL represents hue, saturation and lightness.
✓
HSL can be convenient when creating variations of a color.
05. Common Mistakes
⚠
Using colors with poor contrast.
⚠
Confusing RGB alpha values with hexadecimal values.
⚠
Using too many unrelated colors in one interface.
06. Real World Use
Advanced color formats are used in modern UI systems, gradients, overlays, themes, hover effects and transparent components.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create a Color Palette
Create three boxes using RGB, RGBA and HSL colors. Add a transparent background to one box.