CSS Color System (Color Names, RGB, HEX, HSL)

 

Adding Color to Your Website!

Colors in CSS are like spices in cooking—they bring life and personality to your website! You can define colors using:

  1. Color Names – Simple but limited 
  2. RGB (Red, Green, Blue) – Mix your own shades 
  3. HEX (Hexadecimal) – Compact and precise 
  4. HSL (Hue, Saturation, Lightness) – Intuitive and flexible 

Let’s dive into each method and make your site pop with color!

Color Names: The Simple Way

CSS has 140+ predefined color names, like:

color: red;
color: blue;
color: green;
color: hotpink;
  • Easy to use.
  • Limited selection.

It’s like picking colors from a basic crayon box. 

RGB: Mixing Red, Green, and Blue

RGB lets you mix colors using values from 0 to 255:

color: rgb(255, 0, 0); /* Pure Red */
color: rgb(0, 255, 0); /* Pure Green */
color: rgb(0, 0, 255); /* Pure Blue */
color: rgb(100, 150, 200); /* Custom Shade */
  • Customizable.
  • Supports transparency (rgba).
  • Hard to guess exact colors.

RGB is like mixing paint—you adjust the amounts to get the perfect shade!

HEX: The Web-Friendly Color Code

HEX (hexadecimal) uses six characters (0-9, A-F) to define colors:

color: #ff0000; /* Red */
color: #00ff00; /* Green */
color: #0000ff; /* Blue */
color: #6495ed; /* Cornflower Blue */
  • Compact and widely used.
  • Easy to copy-paste from color pickers.
  • Can be hard to read.

Think of HEX as shorthand for RGB. If you love coding, you’ll love HEX! 

HSL: Hue, Saturation, Lightness 

HSL is more human-friendly than RGB or HEX:

color: hsl(0, 100%, 50%); /* Red */
color: hsl(120, 100%, 50%); /* Green */
color: hsl(240, 100%, 50%); /* Blue */
color: hsl(200, 50%, 70%); /* Soft Blue */
  • Easy to tweak colors.
  • More intuitive than RGB.
  • Less commonly used than HEX.

HSL makes color selection feel like adjusting a Photoshop slider! 

Which One Should You Use?

  • Color Names – Quick and easy, but limited.
  • RGB – Precise but hard to read. 
  • HEX – Web-standard and compact.
  • HSL – Intuitive and flexible.

Now that you know all about CSS colors, go paint your website like a masterpiece! 

Post a Comment

0 Comments