HTML Colors

๐ŸŒˆ Introduction to HTML Colors

Colors in HTML help bring your website to life by changing the appearance of text, backgrounds, borders, and more. You can specify colors using names, HEX codes, RGB values, HSL, and even transparency.

>>โ€œColor does not add a pleasant quality to design โ€” it reinforces it.โ€ โ€” Pierre Bonnard

๐ŸŽฏ Ways to Define Colors in HTML

  • ๐ŸŽจ Color Names (e.g., red, blue)
  • ๐Ÿ“ HEX Codes (e.g., #ff0000)
  • ๐Ÿ”ข RGB Values (e.g., rgb(255, 0, 0))
  • ๐ŸŒ€ HSL Values (e.g., hsl(0, 100%, 50%))
  • ๐Ÿ” RGBA and HSLA for transparency

๐Ÿ’ก Color Name Example

Using Named Colors

<p style="color: red;">This text is red.</p>

๐Ÿงฎ HEX Code Example

Using HEX Colors

<p style="color: #00ff00;">This text is green.</p>

๐Ÿ”ข RGB and RGBA

RGB stands for Red, Green, Blue. You define intensity for each color (0โ€“255). RGBA adds an alpha value for transparency (0.0โ€“1.0).

RGB and RGBA Example

<p style="color: rgb(0, 0, 255);">Blue text</p>
<p style="color: rgba(255, 0, 0, 0.5);">Semi-transparent red text</p>

๐ŸŒ€ HSL and HSLA

HSL stands for Hue, Saturation, Lightness. Just like RGBA, HSLA includes an alpha channel for transparency.

HSL and HSLA Example

<p style="color: hsl(120, 100%, 50%);">Bright green</p>
<p style="color: hsla(120, 100%, 50%, 0.3);">Faded green</p>

๐ŸŒŸ Best Practices

  • Use HEX or HSL for consistent design systems ๐ŸŽฏ
  • For accessibility, ensure sufficient color contrast โš ๏ธ
  • Use CSS variables for scalable color schemes
  • Prefer rgba() or hsla() when you need opacity

๐ŸŽจ Example Palette

Color NameHEXPreview
Red#ff0000
Green#00ff00
Blue#0000ff

๐Ÿ“š Resources to Explore

Note

๐Ÿง  Tip: Test your color combinations using contrast checkers like WebAIM Contrast Checker for better accessibility!
>>โ€œColor is a power which directly influences the soul.โ€ โ€” Wassily Kandinsky ๐ŸŒˆ