agyanadda@gmail.com

HTML Colors

HTML Text & Links 1 min read Updated Nov 30, 2026 Topic 11 of 33

You can set text and background colors with the style attribute (or better, in a CSS file).

Ways to write a color

  • Name: red, navy, tomato
  • HEX: #ff6347 — red, green and blue in hexadecimal
  • RGB: rgb(255, 99, 71) — each value from 0 to 255
  • RGBA: rgba(255, 99, 71, 0.5) — the last value is transparency (0 to 1)
  • HSL: hsl(9, 100%, 64%) — hue, saturation, lightness

All of these can describe the same color.

Example

Example — Text and background colors HTML
<h2 style="color: navy;">Navy heading</h2>
<p style="color: #ff6347;">Tomato text using HEX</p>
<p style="background-color: rgb(255, 235, 59); padding: 8px;">Yellow background using RGB</p>
<p style="background-color: rgba(0, 128, 0, 0.3); padding: 8px;">See-through green using RGBA</p>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which value is a HEX color?

Exercise 2 Fill in the Blank

In rgba(0,0,0,0.5), the last value controls ___.

Frequently Asked Questions

Use the AgyanAdda Color Converter and Gradient tools under Tools to pick colours and copy their codes.