Aral Code

Style & Color Lesson 15 of 42

HTML Colors — Names, HEX and RGB

Learn the three common ways to write colors on the web — color names, HEX codes and RGB — with examples using the colors of the Philippine flag.

Colors make a page feel friendly, serious, playful or professional. On the web you can write a color in a few different ways. This lesson covers the three you'll see most: color names, HEX codes, and RGB.

1. Color names

Browsers understand about 140 color names in English, like red, navy, gold, tomato, teal and whitesmoke. They are easy to remember and great for practice.

Example Named colors
<p style="background-color: tomato; color: white;">tomato</p>
<p style="background-color: gold;">gold</p>
<p style="background-color: seagreen; color: white;">seagreen</p>
<p style="background-color: slateblue; color: white;">slateblue</p>
<p style="background-color: lightgray;">lightgray</p>

The downside: there are only 140 names, so you can't get the exact shade a design needs. For that, we use number codes.

2. RGB — mixing light

Screens make every color by mixing three lights: Red, Green, and Blue. Each one goes from 0 (off) to 255 (full brightness).

  • rgb(255, 0, 0) — only red at full = red
  • rgb(0, 0, 0) — all lights off = black
  • rgb(255, 255, 255) — all lights full = white
  • rgb(255, 255, 0) — red + green = yellow (surprise!)

That last one surprises people who learned color mixing with paint. Light mixes differently from paint: red light + green light makes yellow.

Example RGB colors
<p style="background-color: rgb(255, 0, 0); color: white;">rgb(255, 0, 0)</p>
<p style="background-color: rgb(0, 128, 0); color: white;">rgb(0, 128, 0)</p>
<p style="background-color: rgb(0, 0, 255); color: white;">rgb(0, 0, 255)</p>
<p style="background-color: rgb(255, 255, 0);">rgb(255, 255, 0)</p>
<p style="background-color: rgb(128, 128, 128); color: white;">rgb(128, 128, 128) – gray</p>

That's 256 × 256 × 256 = over 16 million possible colors.

3. HEX codes

HEX is the most common way designers write colors. It's the same RGB idea, just written in hexadecimal (base 16), which uses digits 0–9 and letters A–F. A HEX code starts with # followed by six characters: two for red, two for green, two for blue.

#RRGGBB
#FF0000  → red   (FF = 255 red, 00 green, 00 blue)
#000000  → black
#FFFFFF  → white

You don't need to compute hex numbers by hand. Designers copy them from color pickers. Just know how to read the pattern.

The colors of the Philippine flag

The official flag colors are often written as these HEX codes:

Example Philippine flag colors in HEX
<div style="background-color: #0038A8; color: white; padding: 12px;">Royal blue — #0038A8</div>
<div style="background-color: #CE1126; color: white; padding: 12px;">Scarlet red — #CE1126</div>
<div style="background-color: #FCD116; padding: 12px;">Golden yellow — #FCD116</div>
<div style="background-color: #FFFFFF; padding: 12px; border: 1px solid #ccc;">White — #FFFFFF</div>

Short HEX

When each pair has two identical characters, you can write a 3-character short form: #FF0000 becomes #F00, and #FFFFFF becomes #FFF.

Transparency with rgba

Add a fourth number, called alpha, to make a color see-through. Alpha goes from 0 (invisible) to 1 (solid).

Example rgba transparency
<div style="background-color: #0038A8; padding: 16px;">
  <p style="background-color: rgba(255, 255, 255, 1);">Alpha 1 — solid white</p>
  <p style="background-color: rgba(255, 255, 255, 0.6);">Alpha 0.6</p>
  <p style="background-color: rgba(255, 255, 255, 0.2); color: white;">Alpha 0.2 — almost clear</p>
</div>

Where you can use colors

  • color — text color
  • background-color — the background of an element
  • border — for example border: 3px solid #CE1126;
Example Colored borders
<p style="border: 3px solid #0038A8; padding: 10px;">Blue border</p>
<p style="border: 3px dashed #CE1126; padding: 10px;">Red dashed border</p>

Choosing colors that are easy to read

The most important rule: there must be enough contrast between the text and its background. Light gray text on a white background, or yellow text on white, is very hard to read — especially outdoors on a phone, or for people with weak eyesight.

Example Good vs. bad contrast
<p style="background-color: white; color: #ddd;">Bad: light gray on white is hard to read.</p>
<p style="background-color: yellow; color: white;">Bad: white on yellow.</p>
<p style="background-color: white; color: #222;">Good: dark text on white.</p>
<p style="background-color: #0f5c4d; color: white;">Good: white on dark green.</p>

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. What color is rgb(0, 0, 0)?
2. In #0038A8, which part is the red value?
3. What does the 4th number in rgba(0, 0, 0, 0.5) control?
4. Which pair has the BEST contrast for reading?

By Sir Reyel · Last updated 2026-12-04