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%).
All modern web browsers support 140 standard color names defined by the W3C specification. Below are common examples:
<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 |
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):
<!-- 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) |
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):
<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 |
Search engines reward websites that provide accessible user experiences. According to the Web Content Accessibility Guidelines (WCAG 2.1):
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.
<!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>
256 × 256 × 256 = 16,777,216 distinct colors.
0.0 (completely transparent) to 1.0 (completely opaque).
#F00 expands to #FF0000, #FA3 expands to #FFAA33, and #FFF expands to #FFFFFF.
#ff0000 and #FF0000 render identically in all web browsers. However, uppercase letters are frequently preferred for readability.
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.