Kanbritech Learn logo
HTML HTML Tutorial 45h track

RGB

Write RGB values for white, black, and a middle gray.

Understand the topic

RGB describes the red, green, and blue components of a color. In the common numeric form, each channel ranges from 0 to 255. Equal channels produce shades of gray. An optional alpha value controls opacity, where 0 is transparent and 1 is opaque. Modern CSS permits space-separated channels and a slash before alpha.

Worked example

<p style="background: rgb(220 252 231); color: rgb(20 83 45);">RGB notice</p>
<p style="background: rgb(0 0 0 / 0.1);">Ten percent opaque black background</p>

The first paragraph combines a pale green background with darker green text. Alpha affects the specified color rather than making all child text transparent.

Practice

Write RGB values for white, black, and a middle gray.

Show a suggested answer
white: rgb(255 255 255)
black: rgb(0 0 0)
middle gray: rgb(128 128 128)

Common mistake

Do not put a percentage sign on ordinary 0-to-255 values. Numeric channels and percentage channels use different scales.

HTML documentation

Live Example

Try Coding

Result