Colour swatches with hex codes and RGB sliders

HEX and RGB colors: what the numbers actually represent

HEX and RGB are two ways to write the same kind of channel values in the common sRGB web workflow.

What a HEX color actually means

A six-digit HEX color such as #336699 is a compact way to write three channel values: red, green, and blue. Each channel is written as two hexadecimal digits. The first two digits describe red, the next two describe green, and the last two describe blue. Hexadecimal is base 16, so each pair runs from 00 to ff, which maps to the decimal range 0 to 255. In #336699, red is 0x33 (51), green is 0x66 (102), and blue is 0x99 (153).

HEX notation is popular because it is short, easy to copy from a design tool, and unambiguous once you know the channel order. It does not, by itself, say anything about how bright the color will look on a particular screen, whether it is accessible on a given background, or whether it belongs to a brand palette. Those questions need extra context: the color space, the background, the text size, and the surrounding interface.

What RGB means

RGB notation writes the same three channels as decimal numbers, usually as rgb(51, 102, 153). That is exactly the same color as #336699. The two notations differ only in how the numbers are written: HEX uses base-16 pairs, RGB uses familiar base-10 numbers. When you see rgb(255, 0, 0), you are looking at full red, no green, and no blue, which is the same as #FF0000. When you see rgb(0, 0, 0), that is black; rgb(255, 255, 255) is white.

RGB becomes especially useful when you need an alpha channel, which controls opacity. In modern CSS you can write rgb(51 102 153 / 0.5) or the older rgba(51, 102, 153, 0.5) for the same color at 50 percent opacity. HEX also has an eight-digit form, such as #33669980, where the final 80 is the alpha value in hex (128 out of 255, roughly 50 percent). Both forms describe the same result; choose the one your team finds easier to read and review.

Converting between HEX and RGB: a worked example

To convert HEX to RGB, split the six digits into three pairs and convert each pair from base 16 to decimal. To convert RGB to HEX, convert each decimal channel to a two-digit hexadecimal value, adding a leading zero when the value is below 16.

HEX RGB Notes
#FF0000 rgb(255, 0, 0) Pure red
#00FF00 rgb(0, 255, 0) Pure green
#0000FF rgb(0, 0, 255) Pure blue
#336699 rgb(51, 102, 153) Muted blue; 0x33 = 51, 0x66 = 102, 0x99 = 153
#FFFFFF rgb(255, 255, 255) White
#000000 rgb(0, 0, 0) Black

Work through #336699 by hand once, and the pattern sticks. The pair 33 in hex means 3 times 16 plus 3, which is 51. The pair 66 means 6 times 16 plus 6, which is 102. The pair 99 means 9 times 16 plus 9, which is 153. Going the other way, a decimal value such as 153 divides into 9 sixteens with a remainder of 9, giving 99. If a channel converts to a single hex digit, pad it: decimal 10 becomes 0a, not a, because each channel must occupy exactly two digits in a six-digit HEX color.

Shorthand HEX, named colors, and HSL

Three-digit shorthand HEX such as #369 is a shorter way to write #336699: each digit is doubled. Shorthand is convenient for grays and simple palettes, but it only expresses a subset of colors, because each channel is limited to values like 00, 11, 22, and so on. For precise brand colors, use the full six-digit form.

CSS also provides named colors such as red, rebeccapurple, and transparent. Names are readable, but there are only 148 of them, and they rarely match a brand palette exactly. HSL notation, such as hsl(210, 50%, 40%), describes hue, saturation, and lightness instead of red, green, and blue channels. HSL is often easier when you want to create lighter or darker variants of one hue, because you can adjust the lightness value while keeping the hue steady. HEX and RGB remain the most common notations for handing a precise color from design to code.

Which notation should you use?

Use HEX when you want a short, copy-friendly value for a solid color in a stylesheet, a design token, or a tool. Use RGB or RGBA when you need decimal values for calculations, or when you need an alpha channel in a form your team reads easily. Use HSL when you are building a scale of related shades. The important habit is consistency: pick one primary notation for design tokens, document it, and convert at the edges with a tool rather than by mental arithmetic in production code.

Also record the color space you are assuming. Most web work assumes sRGB. If your project uses a wide-gamut display workflow, a color that looks identical in HEX on two screens can still render differently, because the display and its color profile interpret the numbers. A conversion tool verifies notation; it does not manage color profiles or gamut mapping.

Contrast and accessibility: the notation does not decide readability

The notation does not describe every property of how a monitor displays color. Color profiles, wide-gamut spaces, contrast, and accessibility still matter. Two colors can be perfectly valid HEX values and still be unreadable together. For example, medium gray text on a slightly darker gray background may pass a quick glance but fail a contrast check for body text.

Use a contrast checker and a design-system review when choosing interface colors. A conversion tool verifies notation; it does not decide whether a palette is accessible. Check the actual text size, weight, and state: large bold headings have different contrast expectations than small body copy, and placeholder text, disabled states, and error messages each need their own review. Do not use color alone to communicate status; pair it with text, an icon, or a pattern so the meaning survives for people who cannot perceive the color difference.

Common mistakes

  • Reading HEX channels in the wrong order. HEX is always red, green, blue, not another order.
  • Forgetting to pad a single-digit channel. Decimal 5 becomes 05 in HEX, not 5.
  • Assuming #FFF and #FFFFFF differ. They are the same white; shorthand only shortens the writing.
  • Treating a HEX value as a guarantee of appearance. The same value can look different across displays, brightness settings, and color profiles.
  • Checking contrast once for a single state. Hover, focus, selected, and disabled states can each change the background or text color.
  • Pasting a color without noting its alpha. A translucent color over a light background looks different than the same color over a dark one.

Limitations

HEX and RGB describe channel values, not perception. They do not capture how the human eye weights different wavelengths, how a display calibrates brightness, or how ambient light changes what a reader sees. They also do not encode intent: a token named --brand-blue carries meaning that #336699 alone does not. Keep the token name, the usage guidance, and the contrast evidence alongside the raw value. For print work, remember that screen RGB values and print CMYK values are different models; a color approved on screen still needs a print proof.

FAQ

Q: Are HEX and RGB exactly the same color?

A: Yes, when they describe the same three channel values in the same color space. #336699 and rgb(51, 102, 153) are two spellings of one color. Differences appear only when you add alpha, change color spaces, or round values during conversion.

Q: How do I convert HEX to RGB quickly?

A: Split the six digits into three pairs, convert each pair from hexadecimal to decimal, and write the three decimals as rgb(r, g, b). For a quick check, use the HEX and RGB Color Converter. For values you will ship, verify the result in the actual stylesheet rather than trusting a one-off mental calculation.

Q: What does the alpha in #RRGGBBAA mean?

A: The final two digits are the opacity in hex, from 00 (fully transparent) to FF (fully opaque). #33669980 is the same blue at roughly 50 percent opacity. The visible result depends on whatever is behind the translucent color.

Q: Should I use HEX, RGB, or HSL in a design system?

A: Use one notation as the source of truth for tokens and convert when a specific context needs another form. HEX is the most compact for solid colors; RGB is convenient with alpha; HSL is convenient for building shades. Consistency and documented contrast checks matter more than which notation you pick.

Use the related tool carefully

This guide is paired with a browser-only utility. The tool is a practical aid for small examples and inspection; it is not a substitute for application testing, a formal data pipeline, or professional review where the decision has higher consequences.

Open the related HEX and RGB Color Converter

Sources