HEX vs RGB: 5 Practical Color Examples for CSS

HEX vs RGB is usually a choice of notation, not a choice between different colors. For ordinary CSS values, both can describe the same sRGB color. HEX uses hexadecimal digits; RGB writes the red, green and blue channels as numbers. Transparency adds another detail: preserve the alpha value when converting.

Try the HEX to RGB Converter to see the channels, preview the color and copy the result. The five examples below cover a solid color, shorthand, exact opacity, embedded HEX alpha and a transparent background.

HEX vs RGB at a glance

Format Example Useful when
Six-digit HEX #2563EB Copying a solid brand color
RGB rgb(37, 99, 235) Reading individual channel values
RGBA rgba(37, 99, 235, 0.5) Writing an explicit alpha value
Eight-digit HEX #2563EB80 Keeping color and alpha in one code

1. Convert a solid HEX color to RGB

Split #2563EB into three pairs: 25 for red, 63 for green and EB for blue. Convert each pair from base 16 to decimal. The resulting channel values are 37, 99 and 235.

.button {
  background-color: #2563EB;
}

/* Same solid color */
.button {
  background-color: rgb(37, 99, 235);
}

You do not need to change formats to improve the color itself. Choose the notation your stylesheet or design handoff uses consistently. A converter helps prevent transcription mistakes when one system requests HEX and another requests numeric channels.

2. Expand a three-digit HEX code correctly

For shorthand HEX, repeat each digit rather than adding zeros. The code #3A7 expands to #33AA77, which gives RGB channels 51, 170 and 119.

A common mistake is treating the shorthand as #030A07. That produces a very different color. Paste the original short code into the converter and compare the expanded code with your source before using it.

The MDN reference for HEX colors documents the three-, four-, six- and eight-digit forms. Uppercase and lowercase HEX digits are equivalent.

3. Use RGBA for an exact 50% opacity

To keep the same blue at exactly 50% alpha, write rgba(37, 99, 235, 0.5). In the converter, enter the six-digit code #2563EB and move the opacity slider to 50%.

Modern CSS also supports rgb(37 99 235 / 50%). The MDN rgb() documentation explains the optional alpha component and notes that rgba() is an alias of rgb().

Use one syntax consistently inside a component. Mixing valid notations does not inherently change rendering, but consistent formatting makes reviews easier. When a design brief says “50% opacity,” distinguish that alpha setting from a request to make a color lighter.

4. Preserve the alpha in an eight-digit HEX color

CSS uses the order #RRGGBBAA: the final pair is alpha. In #2563EB80, the color channels are unchanged and the alpha pair is 80. Hexadecimal 80 equals decimal 128, so the alpha is 128 ÷ 255, approximately 0.50196.

This is close to 50%, but not exactly 0.5. If precise 50% alpha is required, use an explicit fractional or percentage value. The CSS Color specification’s HEX notation section describes how the additional pair encodes alpha.

Our converter reads embedded alpha when you enter four- or eight-digit HEX. That embedded value takes precedence over the slider. Its displayed RGBA output rounds alpha to two decimal places, so this example appears as rgba(37, 99, 235, 0.5). Keep the original HEX if you need its exact encoded alpha.

5. Change background transparency without fading the text

A background with alpha and an element with reduced opacity produce different results. For a translucent panel with fully opaque text, apply alpha to the background color:

.panel {
  background-color: rgba(37, 99, 235, 0.5);
  color: #111827;
}

Setting opacity: 0.5 on the panel would fade the whole rendered element, including its text and other contents. The MDN opacity reference explains this distinction.

Preview a translucent panel over its actual background. The same alpha color can look different over white, a dark surface or a photograph. A color conversion preserves channel information; it does not guarantee readable contrast in every layout.

How to use the HEX to RGB Converter

  1. Open the HEX to RGB Converter.
  2. Paste the HEX code into the input.
  3. For a six-digit color, set the opacity slider if needed.
  4. For an alpha-bearing HEX code, check the embedded alpha shown in the result.
  5. Copy the result and test it in your actual stylesheet.

The tool accepts three-, four-, six- and eight-digit inputs. Review the red, green and blue tiles as well as the preview. If the output differs from what you expected, check the code length and alpha before changing the original design.

If you are also building an Arabic version of the page, our HTML direction guide for Arabic text covers a separate part of the implementation: correct direction for mixed text and code-like fragments.

Frequently asked questions

Is HEX more accurate than RGB?

Equivalent channel values and alpha describe the same color. Accuracy depends on preserving those values during conversion.

Does six-digit HEX support transparency?

No alpha is encoded in that form. Use eight-digit HEX or an RGB function with alpha when transparency is needed.

Why does my HEX to RGBA result look different on the page?

Check the background, alpha, inherited styles and element opacity. A transparent color blends with what is behind it.

Convert the value, then check the design

Understanding HEX vs RGB makes it easier to move between design files and CSS without changing the intended color. Preserve the channels, check alpha and preview the final component. Use the free HEX to RGB Converter to compare formats before copying them into your project.

Related tools