Nearby lessons

7 of 24

🎨 HTML Colors

πŸ“Œ What are HTML Colors?

HTML colors let you style your text, backgrounds, and borders. You can use color names (red), HEX codes (#ff0000), RGB (rgb(255, 0, 0)), and more!

πŸ–οΈ Text Colors

To change text color, use the color property in inline styles or CSS.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

🌈 Background Colors

Use the background-color property to color page backgrounds or sections. You can use HEX, RGB, RGBA, or HSL values.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

πŸ–ŒοΈ Border Colors

Set border color using the border or border-color property.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

βœ… Best Practices for Using Colors

  • 🎯 Make sure there's enough contrast for readability (WCAG 2.1 AA)
  • πŸ”– Use CSS variables like --primary-color for consistency
  • 🚫 Don’t use color alone to show meaning β€” combine with text or icons
  • 🎭 Use RGBA/HSLA for transparency effects
  • πŸŒ— Test your design in both light and dark modes if applicable

πŸ“˜ Common Color Names Table

AttributeDescription
πŸ”΄ RedHEX: #FF0000, RGB: rgb(255, 0, 0)
🟒 GreenHEX: #008000, RGB: rgb(0, 128, 0)
πŸ”΅ BlueHEX: #0000FF, RGB: rgb(0, 0, 255)
🟑 YellowHEX: #FFFF00, RGB: rgb(255, 255, 0)
⚫ BlackHEX: #000000, RGB: rgb(0, 0, 0)
βšͺ WhiteHEX: #FFFFFF, RGB: rgb(255, 255, 255)

🧠 Test Your Knowledge

4 Questions

Progress: 0 / 4
Keep Going!HTML Div