HTML RGB Colors
In this page:
<tagname style="color: rgb(red, green, blue);">content</tagname>
<tagname style="color: rgba(red, green, blue, alpha);">content</tagname>
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.
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.
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.
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.
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.
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