HTML Colors

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:
Color Names
RGB Values
HEX Values
HSL Values
1. Color Names
HTML supports 140+ predefined color names.
- Easy to use
- Limited control
2. RGB Colors (Red, Green, Blue)
Format:
Each value ranges from 0 to 255.
RGB with Transparency (RGBA)
3. HEX Colors (Most Popular)
Format:
- Widely used
- Precise control
- Best for web design
4. HSL Colors (Hue, Saturation, Lightness)
Format:
HSLA (with opacity)
Background Colors
Border Colors
Text + Background Example
Quick Comparison Table
| Method | Example | Use Case |
|---|---|---|
| Color Name | red | Simple styling |
| RGB | rgb(255,0,0) | Dynamic colors |
| HEX | #FF0000 | Web standard |
| HSL | hsl(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

