HTML Colors

HTML Tutorial

HTML Colors

HTML colors are used to style text, backgrounds, borders, and other elements. Colors are usually applied using CSS, either inline or via stylesheets.

Ways to Define Colors in HTML

There are 4 common ways to specify colors:

  1. Color Names

  2. RGB Values

  3. HEX Values

  4. HSL Values

HTML Colors

1. Color Names

HTML supports 140+ predefined color names.

  •  Easy to use
  •  Limited control

2. RGB Colors (Red, Green, Blue)

Format:

rgb(red, green, blue)

Each value ranges from 0 to 255.

RGB with Transparency (RGBA)

3. HEX Colors (Most Popular)

Format:

#RRGGBB
  • Widely used
  •  Precise control
  •  Best for web design

4. HSL Colors (Hue, Saturation, Lightness)

Format:

hsl(hue, saturation%, lightness%)

HSLA (with opacity)

Background Colors

Border Colors

Text + Background Example

Quick Comparison Table

MethodExampleUse Case
Color NameredSimple styling
RGBrgb(255,0,0)Dynamic colors
HEX#FF0000Web standard
HSLhsl(0,100%,50%)Design-friendly

Best Practices

  •  Prefer HEX or RGB for professional projects
  •  Use RGBA / HSLA for transparency
  •  Avoid too many bright colors
  •  Maintain good contrast for readability

You may also like...