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
π 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
ποΈ Border Colors
Set border color using the border or border-color property.
Code Example
PREVIEW READY
β Best Practices for Using Colors
- π― Make sure there's enough contrast for readability (WCAG 2.1 AA)
- π Use CSS variables like
--primary-colorfor 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
| Attribute | Description |
|---|---|
π΄ Red | HEX: #FF0000, RGB: rgb(255, 0, 0) |
π’ Green | HEX: #008000, RGB: rgb(0, 128, 0) |
π΅ Blue | HEX: #0000FF, RGB: rgb(0, 0, 255) |
π‘ Yellow | HEX: #FFFF00, RGB: rgb(255, 255, 0) |
β« Black | HEX: #000000, RGB: rgb(0, 0, 0) |
βͺ White | HEX: #FFFFFF, RGB: rgb(255, 255, 255) |
π§ Test Your Knowledge
4 QuestionsProgress: 0 / 4
Keep Going!HTML Div