Unit 1: Core CSS Foundations & SyntaxLesson #2 / 8

Lesson 2: HSL Colors, Hex Codes & Linear Gradients

Er. Manoj Kumar — AuthorEr. Manoj KumarLast Updated: 26 Aug, 2026

1. Modern CSS Color Systems

CSS provides multiple precise formats to define visual color on computer screens:

  • Hex Codes (#04AA6D): 6-digit hexadecimal format representing Red, Green, and Blue channels.
  • RGB / RGBA (rgba(4, 170, 109, 0.9)): Numerical intensity from 0 to 255 with an optional alpha opacity channel (0.0 to 1.0).
  • HSL / HSLA (hsla(158, 95%, 34%, 1)): Human-friendly Hue (0-360°), Saturation (0-100%), and Lightness (0-100%).
  • HTML5 Web Code (index.html)
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>CSS Color & Gradient Studio</title>
    <style>
    body {
    background-color: #17181c;
    color: #ffffff;
    font-family: Arial, sans-serif;
    padding: 24px;
    }
    .gradient-banner {
    background: linear-gradient(135deg, #04AA6D 0%, #025335 100%);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(4, 170, 109, 0.2);
    }
    .color-pill {
    display: inline-block;
    padding: 8px 16px;
    margin: 8px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 13px;
    }
    .hex-box { background-color: #04AA6D; color: #fff; }
    .rgb-box { background-color: rgb(32, 201, 151); color: #000; }
    .hsl-box { background-color: hsl(158, 95%, 34%); color: #fff; }
    </style>
    </head>
    <body>
    <div class="gradient-banner">
    <h2>Vibrant CSS Color & Linear Gradients</h2>
    <p>Curated color systems create stunning, modern user interfaces.</p>
    <div class="color-pill hex-box">HEX: #04AA6D</div>
    <div class="color-pill rgb-box">RGB: (32, 201, 151)</div>
    <div class="color-pill hsl-box">HSL: (158, 95%, 34%)</div>
    </div>
    </body>
    </html>

    2. Linear & Radial Gradients

  • Linear Gradient: Transitions colors along a straight line angle (to right, 135deg, to bottom).
  • Radial Gradient: Radiates colors outward from a circular center point (radial-gradient(circle, #04AA6D, #17181c)).
  • Interactive Knowledge Check

    Test your understanding of Lesson #2 concepts

    In the HSL color model hsl(120, 100%, 50%), which color does the Hue angle 120 degrees represent?