HTML Colors

Colour names, HEX, RGB and HSL values.

✍️ 3 exercises + code challenge in this lesson

Colours in HTML and CSS can be written in several ways:

  • Names: tomato, navy, teal (about 140 names are supported).
  • HEX: #RRGGBB, e.g. #2563EB.
  • RGB: rgb(37, 99, 235), each value from 0 to 255.
  • RGBA: adds transparency, e.g. rgba(37, 99, 235, 0.5).
  • HSL: hue, saturation, lightness, e.g. hsl(221, 83%, 53%).

Key Takeaways: HTML Colors

Mastering HTML Colors helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

HTML Colors Code Example

HTML
<h2 style="background-color: tomato; color: white;">Colour name</h2>
<h2 style="background-color: #2563EB; color: white;">HEX #2563EB</h2>
<h2 style="background-color: rgb(20, 184, 166); color: white;">rgb(20, 184, 166)</h2>
<h2 style="background-color: rgba(37, 99, 235, 0.4);">rgba with 40% opacity</h2>
<h2 style="background-color: hsl(45, 93%, 47%);">hsl(45, 93%, 47%)</h2>
Free sign-in required · Google login available

HTML Colors Practice Exercises

Check what you learned in “HTML Colors”.

/ 3 solved
Fill in the blank

Write the colour value in HEX for pure white.

<p style="color: ;">Text</p>
✓ Correct! Not quite. Try again.
Multiple choice

What does the "a" in rgba() control?

✓ Correct! Not quite. Try again.
Code challenge

Give the <div> the background colour rgb(255, 99, 71) (tomato).

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services