HTML - Color

In HTML, colors can be specified using a variety of formats depending on precision and transparency needs. The most widely used color systems include:

      Color Names: Standard predefined names like Red, Green, Blue, Tomato, and DodgerBlue.

      RGB Values: Additive Red-Green-Blue light intensities from 0 to 255 (e.g., rgb(0, 255, 0)).

      HEX Codes: Hexadecimal representation of RGB channels (e.g., #FF0000 or shorthand #F00).

      RGBA Values: RGB extended with an Alpha channel for transparency from 0.0 (invisible) to 1.0 (opaque).

      HSL / HSLA Values: Cylindrical color coordinates based on Hue (0-360°), Saturation (0-100%), and Lightness (0-100%).


1. HTML Color Names

All modern web browsers support 140 standard color names defined by the W3C specification. Below are common examples:

Syntax & Example:


<h3 style="background-color: Orange; color: white; padding: 10px;">Orange Background</h3>
<h3 style="background-color: Crimson; color: white; padding: 10px;">Crimson Background</h3>
							

Color Swatch

Standard Name

Hex Equivalent

Orange

#FFA500

Red

#FF0000

Green

#008000

Yellow

#FFFF00

Blue

#0000FF


2. RGB & RGBA Values (Light Intensity & Opacity)

An RGB color value represents the red, green, and blue light parameters: rgb(red, green, blue). Each parameter defines the color intensity between 0 and 255. In modern HTML5 and CSS3, RGBA adds an alpha transparency channel (0.0 to 1.0):

Syntax & Example:


<!-- Solid RGB Color -->
<p style="background-color: rgb(255, 0, 0); color: white;">Pure Red RGB</p>

<!-- Semi-transparent RGBA Color (50% Opacity) -->
<p style="background-color: rgba(0, 128, 0, 0.5); color: black;">50% Transparent Green</p>
							

Color Swatch

RGB / RGBA Formula

Resulting Tone

rgb(255, 140, 0)

Dark Orange

rgb(255, 0, 0)

Pure Red

rgb(0, 128, 0)

Pure Green

rgb(0, 0, 255)

Pure Blue

rgba(0, 0, 255, 0.3)

Light Blue (30% Opacity Overlay)


3. Hexadecimal (HEX) Colors

Hexadecimal color notation is the most popular format among web developers. A hex color is specified with: #RRGGBB, where RR (red), GG (green), and BB (blue) are hexadecimal integers between 00 and FF (0 to 255 in decimal):

Syntax & Example:


<h3 style="background-color: #FF8C00; color: white;">Dark Orange via HEX</h3>
<h3 style="background-color: #2ECC71; color: white;">Emerald Green via HEX</h3>
							

Color Swatch

6-Digit HEX Code

3-Digit Shorthand

#FF0000

#F00

#00FF00

#0F0

#0000FF

#00F

#FFFFFF

#FFF

#000000

#000


Web Accessibility: Color Contrast for SEO & Readability

Search engines reward websites that provide accessible user experiences. According to the Web Content Accessibility Guidelines (WCAG 2.1):

  • Normal body text must maintain a contrast ratio of at least 4.5:1 against its background.
  • Large headings (18pt / 24px and above) require a contrast ratio of at least 3:1.
  • Never use low-contrast combinations like light gray text on a white background, or dark blue text on a black background. Poor contrast increases bounce rates and reduces search rankings.
Interactive Color Tool: Looking for exact RGB and HEX hex codes for your website project? Visit our free Online Color Picker Tool .

Hands-on Practice Session for Students

Lab Assignment 11: Build a UI Alert Component System Using Different Color Formats.

Problem Statement: Create four notification alert boxes for a website: Success (Green HEX), Warning (Yellow RGB), Error (Red Name), and Info (Transparent Blue RGBA). Ensure all text meets accessibility contrast standards.

Solution Code:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Color System - BCA Practical 11</title>
    <style>
        .alert-box {
            padding: 12px 18px;
            margin-bottom: 12px;
            border-radius: 4px;
            font-family: Arial, sans-serif;
            font-size: 15px;
        }
        .success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .warning { background-color: rgb(255, 243, 205); color: rgb(133, 100, 4); }
        .error   { background-color: #f8d7da; color: Crimson; border: 1px solid #f5c6cb; }
        .info    { background-color: rgba(0, 123, 255, 0.15); color: #004085; }
    </style>
</head>
<body>
    <h2>Veewom System Notifications</h2>
    <div class="alert-box success"><strong>Success:</strong> Form submitted successfully via HEX color!</div>
    <div class="alert-box warning"><strong>Warning:</strong> Session expires in 5 minutes via RGB color.</div>
    <div class="alert-box error"><strong>Error:</strong> Invalid input detected using named color Crimson.</div>
    <div class="alert-box info"><strong>Info:</strong> New tutorial available using RGBA transparency.</div>
</body>
</html>
							

Viva & University Exam Questions (BCA Exam Preparation)

Because each channel (Red, Green, Blue) has 256 possible intensity values (from 0 to 255), the total number of unique color combinations is 256 × 256 × 256 = 16,777,216 distinct colors.
RGB defines only the red, green, and blue color channels. RGBA adds a fourth parameter—the Alpha channel—which specifies the transparency/opacity of the color on a scale from 0.0 (completely transparent) to 1.0 (completely opaque).
When both digits in each RGB pair are identical, the 6-digit hex code can be shortened to 3 digits. The browser automatically duplicates each character: #F00 expands to #FF0000, #FA3 expands to #FFAA33, and #FFF expands to #FFFFFF.

Frequently Asked Questions (FAQ)

No. Hexadecimal color codes are case-insensitive: #ff0000 and #FF0000 render identically in all web browsers. However, uppercase letters are frequently preferred for readability.
The CSS opacity property makes the entire element—including its background, borders, and all child text—transparent. In contrast, rgba() background color makes only the background transparent, keeping inner text crisp, solid, and easily readable.
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!