HTML RGB Colors
In this page:
The Three Light Channels
rgb(red, green, blue) takes three numbers from 0 to 255 that represent the intensity of red, green, and blue light mixed together on screen. Higher numbers mean brighter light for that channel, so rgb(255, 0, 0) is pure red at full intensity with the other two channels completely off.
Note: Think of RGB as mixing colored spotlights, not paint -- combining all three at full brightness produces white, not brown or black.
Warning: Values outside the 0-255 range are invalid and will be ignored or clamped by the browser.
Example: The Three Light Channels
<p style="color: rgb(255, 0, 0);">Pure red text</p>
Mixing Channels for Custom Colors
Combining different intensities across the three channels produces custom colors -- rgb(255, 165, 0) mixes full red with medium green and no blue to produce orange. Millions of distinct colors are reachable this way, far beyond the 140 named CSS color keywords.
Note: Use an online color picker to find the exact rgb() values for a brand color before hand-guessing the mix.
Warning: Small changes to a single channel can shift a color noticeably, so test custom RGB mixes visually rather than assuming the math.
Example: Mixing Channels for Custom Colors
<p style="color: rgb(255, 165, 0);">Orange text</p>
Shades of Gray
Setting all three channels to the exact same value produces a shade of gray -- rgb(0, 0, 0) is black, rgb(255, 255, 255) is white, and any equal value in between, like rgb(128, 128, 128), is a mid-tone gray. This makes RGB an easy way to build a consistent grayscale palette.
Note: Use equal RGB values for grayscale UI elements like borders and dividers to keep them perfectly neutral with no color tint.
Warning: Slightly unequal channel values that look gray at a glance can carry a faint, unintended color tint when zoomed in.
Example: Shades of Gray
<p style="color: rgb(128, 128, 128);">Mid-tone gray text</p>
Adding Transparency with rgba()
rgba(red, green, blue, alpha) adds a fourth value called alpha, ranging from 0 (fully transparent, invisible) to 1 (fully opaque, solid), letting a color blend with whatever sits behind it. This is commonly used for semi-transparent overlays on top of images or other page content.
Note: Use rgba() with a low alpha value like 0.5 to create a translucent overlay that still lets background content show through.
Warning: An alpha value of 0 makes the color completely invisible, which can look like the background-color rule silently did nothing.
Example: Adding Transparency with rgba()
<div style="background-color: rgba(0, 0, 0, 0.5);">Semi-transparent overlay</div>
RGB in Inline Styles and CSS Rules
RGB and RGBA values work identically whether used in an HTML inline style attribute or inside an external CSS stylesheet, and can be applied to any property that accepts a color, including color, background-color, border-color, and box-shadow.
Note: Keep RGB color values consistent across a project by storing frequently used mixes in CSS custom properties instead of retyping the numbers.
Warning: Copy-pasting rgb() values between properties without checking commas and parentheses is a common source of invalid CSS syntax.
Example: RGB in Inline Styles and CSS Rules
<style>
.box { border-color: rgb(0, 128, 255); }
</style>
<div class="box" style="color: rgb(200, 0, 0);">Styled with RGB</div>
- Typing rgb values above 255 or below 0, when each channel is clamped to the 0-255 range and anything outside it is simply invalid.
- Forgetting that rgb(0,0,0) is black (all lights off) while rgb(255,255,255) is white (all lights at full brightness), which is the reverse of how mixing paint pigments works.
- Using rgba() without realizing the fourth value is opacity from 0 (fully transparent) to 1 (fully opaque), not a fourth color channel.
- RGB colors are written as rgb(red, green, blue), with each channel ranging from 0 to 255.
- Equal values for all three channels produce a shade of gray, from rgb(0,0,0) black to rgb(255,255,255) white.
- rgba() adds a fourth transparency channel, letting you layer semi-transparent colors over backgrounds and images.
rgb() and rgba() color notation is supported in every browser back to the earliest CSS2/CSS3 implementations.
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists