HTML Colors & RGB0%

HTML Colors & RGB

Beginner8 min readβ€’Updated: 2026-09-10
Study Materials

HTML Colors & RGB / RGBA (Painting Your Webpage) 🎨

Welcome to Chapter 5: Colors in HTML!

Imagine you are making a project poster for your school's Annual Science Exhibition. If you only write on a plain white chart paper using a black ballpoint pen, it looks boring and dull.

Now imagine picking up your watercolor box, sketch pens, and bright highlighters:

  • You give your main title a bold Crimson Red banner!
  • You write your key points inside a pleasant Sky Blue card!
  • You highlight important formulas in warm Gold / Yellow!

Instantly, everyone stopping by your stall wants to read your poster! On websites, colors perform the exact same magic. They give your website life, emotion, and personality.

In this lesson, you will learn the first two exciting ways to paint your webpages:

  1. 1
    Built-in Color Names (Simple words like Tomato and DodgerBlue).
  2. 2
    RGB & RGBA Colors (Mixing Red, Green, and Blue light like a digital artist!).

How Does HTML Apply Colors? (A Quick Look)

In HTML, we usually add colors to elements using the style attribute (which uses simple CSS styling rules).

Here are the three most common ways you will use colors:

HTML
<!-- 1. Text Color: Changes the color of letters -->
<h1 style="color: Tomato;">Welcome to My School Website</h1>
Β 
<!-- 2. Background Color: Paints the box behind the text -->
<p style="background-color: LightYellow; color: DarkSlateGray; padding: 10px;">
Exam Notice: Unit tests begin from next Monday!
</p>
Β 
<!-- 3. Border Color: Draws a colored outline around an element -->
<div style="border: 3px solid DodgerBlue; padding: 15px;">
Important Announcement Box
</div>

Now let's dive into how you tell the browser which color you want!


Method 1: Built-in Color Names 🏷️

Web browsers are super smart. They understand 140 official standard color names in plain English!

You do not need to memorize any numbers. Just write the name of the color inside your style tag, and the browser displays it immediately!

Color NameWhat It Looks LikeWhere to Use It
TomatoVibrant reddish-orangeUrgent alerts, important warnings
DodgerBlueCrisp, friendly sky blueLinks, buttons, school headers
MediumSeaGreenFresh, clean leafy greenSuccess messages, passed test scores
OrangeWarm, energetic citrusBadges, call-out highlights
GoldRich sunshine yellowTrophy awards, star ratings
CrimsonDeep, royal dark redMajor announcements, badges
DarkSlateGraySoft dark charcoalEasy-to-read paragraph text
Snow / WhiteClean pure whiteBackgrounds and card surfaces

Complete Example with Color Names:

HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>School Club Notice</title>
</head>
<body style="background-color: Snow; font-family: Arial, sans-serif;">
Β 
<!-- Heading in Tomato Red -->
<h1 style="color: Tomato;">Robotics Club - Annual Registration</h1>
Β 
<!-- Info box with DodgerBlue border and LightCyan background -->
<div style="background-color: LightCyan; border: 2px solid DodgerBlue; padding: 15px;">
<h3 style="color: DodgerBlue;">Open for Classes 8th to 12th</h3>
<p style="color: DarkSlateGray;">
Learn how to build drones, line-follower cars, and smart home gadgets!
</p>
<p style="color: MediumSeaGreen; font-weight: bold;">
Status: Admissions Open (Free Entry)
</p>
</div>
Β 
</body>
</html>

The Limitation of Color Names:

Color names are super easy and fast. But you only have 140 names! What if your school logo has a very specific shade of peacock blue, or you want a soft pastel mango color that does not have an official name?

For that precision, we use RGB!


Method 2: RGB Colors (Mixing Light Bulbs) πŸ’‘

When you paint on paper, you mix liquid paints like red, yellow, and blue.

But your computer monitor, tablet, and mobile phone screen are made of millions of tiny microscopic light bulbs called pixels. Each pixel contains three tiny colored lights:

  1. 1
    R = Red
  2. 2
    G = Green
  3. 3
    B = Blue
Output
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ THE RGB SCREEN PIXEL β”‚
β”‚ β”‚
β”‚ [ RED ] + [ GREEN ] + [ BLUE ] β”‚
β”‚ (0 - 255) (0 - 255) (0 - 255) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

In HTML and CSS, we write RGB colors like a small formula:

$$\text{rgb(red, green, blue)}$$

How the Numbers Work:

For each color light, you pick a number from 0 to 255:

  • 0 means the light bulb is turned completely OFF (0% brightness).
  • 255 means the light bulb is shining at MAXIMUM brightness (100% full power).

Because each of the 3 lights can have 256 different values ($0$ to $255$), you can create: $$256 \times 256 \times 256 = 16,777,216\text{ different color shades!}$$

That is over 16.7 million colors!


Exploring RGB Color Mixing:

Let's see what happens when we adjust the light switches:

ColorRGB FormulaHow It Works (The Light Bulb Analogy)
Pure Redrgb(255, 0, 0)Red light full power (255), Green & Blue are completely OFF (0).
Pure Greenrgb(0, 255, 0)Green light full power (255), Red & Blue are OFF (0).
Pure Bluergb(0, 0, 255)Blue light full power (255), Red & Green are OFF (0).
Pitch Blackrgb(0, 0, 0)All three lights are OFF! Like standing in a dark room with no torch.
Bright Whitergb(255, 255, 255)All three lights are shining at maximum power together!
Yellowrgb(255, 255, 0)Red + Green mixed together at full power make bright yellow!
Cyan (Aqua)rgb(0, 255, 255)Green + Blue lights mixed together make electric cyan.
Magenta (Pink/Purple)rgb(255, 0, 255)Red + Blue lights mixed together make vibrant magenta.
MSK Orangergb(255, 107, 0)Red full (255), Green medium (107), Blue OFF (0).
Medium Grayrgb(128, 128, 128)All three lights set equally to half power create smooth gray.

Code Example:


Method 3: RGBA (Adding See-Through Transparency) πŸͺŸ

Have you ever looked through a pair of tinted sunglasses, a frosted bathroom glass, or butter tracing paper in your art class?

When you look through tinted sunglasses:

  • You can still see the trees and buildings behind the glass.
  • But everything has a soft dark tint over it.

That "see-through" property is called transparency (or opacity).

In web design, whenever you want a color to be semi-transparent, you add a fourth letter: A for Alpha!

$$\text{rgba(red, green, blue, alpha)}$$

Output
rgba( 255, 107, 0, 0.5 )
─── ─── ─── ───
β”‚ β”‚ β”‚ β”‚
Red Green Blue Alpha (50% See-Through)

How the Alpha Value Works:

The Alpha value is a decimal number between 0.0 and 1.0:

Alpha ValueTransparency LevelReal-World Analogy
0.00% Solid (100% Invisible)Completely clear air. You cannot see the color at all!
0.220% Solid (80% See-Through)Extremely light tint, like clean window glass with water droplets.
0.550% Solid (Half See-Through)Tracing paper or tinted sunglasses. Half color, half background shows through!
0.880% Solid (20% See-Through)Dark sunshade in a car. Mostly solid with a hint of background.
1.0100% Solid (Fully Opaque)A solid brick wall! Zero background shows through (acts just like normal RGB).

Practical Example with RGBA:

Notice how modern websites have floating glass cards or darkened overlay menus. RGBA makes that super easy:

HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RGBA Transparency Demo</title>
</head>
<body style="background-color: rgb(15, 23, 42); font-family: Arial, sans-serif; padding: 20px;">
Β 
<!-- Completely opaque solid white heading -->
<h1 style="color: rgb(255, 255, 255);">Welcome to Science Lab</h1>
Β 
<!-- Card with 80% opacity dark background -->
<div style="background-color: rgba(255, 255, 255, 0.15); color: rgb(255, 255, 255); padding: 20px; border-radius: 8px;">
<h3>Glass Card Notice</h3>
<p>Notice how the dark background subtly shines through this white tinted card!</p>
</div>
Β 
<!-- Warning banner with semi-transparent red -->
<div style="background-color: rgba(239, 68, 68, 0.25); color: rgb(254, 202, 202); border: 1px solid rgba(239, 68, 68, 0.6); padding: 12px; margin-top: 15px; border-radius: 6px;">
<strong>Alert:</strong> Chemistry lab is closed for sanitization today.
</div>
Β 
</body>
</html>

Color Names vs RGB vs RGBA: Quick Comparison

FeatureBuilt-in Color NamesRGBRGBA
Syntaxcolor: Tomato;color: rgb(255, 99, 71);color: rgba(255, 99, 71, 0.5);
Number of Choices140 pre-set names16.7+ Million shades16.7+ Million shades
Transparency Support❌ No❌ No (always solid)βœ… Yes (0.0 to 1.0)
Ease of UseVery easy to rememberEasy once you know Red, Green, BlueGreat for overlays & glass effects
Best ForQuick tests & simple school pagesExact custom brand colorsModern UI cards, modals & popups

Common Beginner Mistakes (And How to Avoid Them) ⚠️

1. ⚠️ Spelling "colour" instead of "color"

In India and the Commonwealth, we spell it as colour in our English notebooks. But web programming standards were written in American English!

2. ⚠️ Writing numbers greater than 255 in RGB

The maximum limit for Red, Green, and Blue is 255.

HTML
<!-- ❌ WRONG: 300 is invalid! -->
<p style="color: rgb(300, 0, 0);">Error</p>
Β 
<!-- βœ… CORRECT: Maximum value is 255 -->
<p style="color: rgb(255, 0, 0);">Pure Red</p>

3. ⚠️ Giving Alpha a whole number or percentage

The fourth parameter in rgba() must be a decimal between 0.0 and 1.0.

HTML
<!-- ❌ WRONG: 50 is treated as 1.0 or an invalid value -->
<p style="background-color: rgba(0, 0, 0, 50);">Error</p>
Β 
<!-- βœ… CORRECT: Use 0.5 for 50% opacity -->
<p style="background-color: rgba(0, 0, 0, 0.5);">Semi-transparent</p>

4. ⚠️ Forgetting commas between numbers

Always separate the numbers in RGB with a comma.

HTML
<!-- ❌ WRONG: Missing commas -->
<p style="color: rgb(255 0 0);">Missing commas</p>
Β 
<!-- βœ… CORRECT: Comma-separated -->
<p style="color: rgb(255, 0, 0);">Perfect</p>

Quick Summary

  • HTML allows you to add colors using the inline style attribute (color for text, background-color for backgrounds, border for outlines).
  • HTML supports 140 built-in color names (like Tomato, DodgerBlue, Gold, and MediumSeaGreen).
  • RGB stands for Red, Green, Blueβ€”the three primary colored light bulbs inside your computer and mobile screen.
  • In rgb(r, g, b), each channel ranges from 0 (light completely OFF) to 255 (light shining at 100% full power).
  • rgb(0, 0, 0) is Black (all lights off); rgb(255, 255, 255) is White (all lights shining full power).
  • RGBA adds the Alpha channel for transparency, ranging from 0.0 (completely see-through) to 1.0 (completely solid).
  • Always use the American spelling color in your HTML and CSS code!

Practice Quiz

Test your understanding with these multiple-choice questions:

1. Which of the following is NOT one of the 3 primary light channels in the RGB model?

A. Red B. Yellow C. Green D. Blue Answer: B Explanation: Computer screens mix Red, Green, and Blue light (RGB). Yellow is formed digitally by mixing Red and Green light together!


2. What color is produced by rgb(0, 0, 0)?

A. Pure White B. Bright Yellow C. Pitch Black D. Dark Gray Answer: C Explanation: When Red, Green, and Blue lights are all set to 0, all light bulbs are turned off, producing total darkness (Black).


3. What is the maximum number you can provide for any color channel in rgb(r, g, b)?

A. 100 B. 250 C. 255 D. 500 Answer: C Explanation: Each color channel in RGB uses an 8-bit value ranging from 0 to 255 (a total of 256 levels of brightness).


4. What does the "A" stand for in the RGBA color format?

A. Angle B. Alpha (Transparency / Opacity) C. Amber D. Alignment Answer: B Explanation: Alpha specifies the transparency or opacity level, using a decimal number between 0.0 (invisible) and 1.0 (fully solid).


5. If you want a semi-transparent black background at 50% opacity, which code should you write?

A. rgba(0, 0, 0, 50%) B. rgba(0, 0, 0, 0.5) C. rgb(0, 0, 0, 50) D. rgba(255, 255, 255, 0.5) Answer: B Explanation: Black is 0, 0, 0, and 50% opacity is represented as decimal 0.5 in RGBA.


Hands-on Practice Challenge 🎯

Open your favorite text editor (like VS Code) and create a file named tricolor-card.html.

Your Challenge:

Create a special greeting card celebrating India's National Flag (Tiranga) using what you learned today:

  1. 1
    Create a top band with Saffron / Orange using RGB: rgb(255, 153, 51).
  2. 2
    Create a middle band with White background: rgb(255, 255, 255) with text in Navy Blue (rgb(0, 0, 128)).
  3. 3
    Create a bottom band with India Green using RGB: rgb(19, 136, 8).
  4. 4
    Add a nice semi-transparent footer note at the bottom using RGBA: rgba(0, 0, 0, 0.05).
  5. 5
    Open the file in your web browser and admire your colorful creation!

Next Up: In Topic 5.2, we will explore HEX Codes and HSLβ€”the industry-standard color secrets used by professional UI/UX designers and web developers worldwide!

Next Lesson

HEX & HSL Color Codes

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
HTML CommentsHEX & HSL Color Codes

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext