Colors in HTML
? Colors in HTML
In HTML, colors are used to style text, backgrounds, borders, and more. You typically control colors with CSS, but you specify color values in various formats.
Ways to Specify Colors
1. Color Names
Simple names like:
<p style="color: red;">Red text</p>Common color names: red, blue, green, black, white, yellow, orange, purple, pink, etc.
2. Hexadecimal (Hex) Colors
Starts with # followed by 3 or 6 hexadecimal digits (0-9, A-F):
<p style="color: #FF0000;">Red text</p>#FF0000= Red#00FF00= Green#0000FF= BlueShort form:
#F00=#FF0000
3. RGB Colors
Define red, green, blue components (0–255):
<p style="color: rgb(255, 0, 0);">Red text</p>4. RGBA Colors (RGB + Alpha for transparency)
Alpha goes from 0 (transparent) to 1 (opaque):
<p style="color: rgba(255, 0, 0, 0.5);">Semi-transparent red</p>5. HSL Colors
Hue, Saturation, Lightness:
<p style="color: hsl(0, 100%, 50%);">Red text</p>Example: Styling Text and Background Colors
<p style="color: white; background-color: #007BFF;"> White text on blue background</p>Summary
| Format | Example | Notes |
|---|---|---|
| Color Name | red | Easy but limited colors |
| Hex | #FF5733 | Most common in web design |
| RGB | rgb(255,87,51) | Precise control |
| RGBA | rgba(255,87,51,0.7) | Transparency |
| HSL | hsl(9,100%,60%) | Intuitive color adjustment |
Want me to help you generate color palettes or show you how to use colors in CSS files?