HTML Colors
Subject: html
HTML Colors
Color is essential in web design for creating visual hierarchy, enhancing readability, and guiding user attention. HTML supports multiple color formats using CSS: named colors, HEX, RGB, and HSL.
šØ 1. Using Named Colors
HTML supports over 140 predefined color names.
Popular color names include:
- red
- blue
- green
- black
- white
- gray
- tomato
- gold
š Named colors are quick and easy to use but lack the precision of other formats.
š 2. RGB (Red, Green, Blue)
What is RGB?
- RGB stands for Red, Green, Blue.
- Each color component ranges from 0 to 255.
Syntax:
Example:
Explanation:
rgb(255, 0, 0)
ā Full redrgb(0, 255, 0)
ā Full greenrgb(0, 0, 255)
ā Full blue
ā RGB offers fine control over color intensity.
š¢ 3. HEX (Hexadecimal Codes)
What is HEX?
- HEX uses base-16 notation to define colors.
- Format:
#RRGGBB
, where RR, GG, and BB range from 00 to FF.
Example:
Shorthand HEX:
#FFF
ā white (#FFFFFF
)#000
ā black (#000000
)
ā HEX codes are compact and widely used in design tools and CSS.
š 4. HSL (Hue, Saturation, Lightness)
What is HSL?
- Hue: 0ā360° on the color wheel (0 = red, 120 = green, 240 = blue)
- Saturation: 0% (gray) to 100% (full color)
- Lightness: 0% (black) to 100% (white)
Syntax:
Example:
ā HSL is intuitive for generating color themes and adjusting brightness.
šØ 5. Applying Colors in HTML Elements
You can apply colors directly using the style
attribute:
ā Summary of Color Formats
Format | Example | Description |
---|---|---|
Named Color | red , blue | Easy and readable |
HEX | #FF0000 | Compact, common in design tools |
RGB | rgb(255,0,0) | Precise color definition |
HSL | hsl(0, 100%, 50%) | Intuitive for color manipulation |
š Key Takeaway
Understanding and choosing the right color format in HTML enables you to design visually appealing and accessible websites. Use named colors for simplicity, RGB or HEX for precision, and HSL when flexibility and visual control are needed.
Advertisement Slot 1
Advertisement Slot 2