Skip to content
Software and the Internet

How to convert HEX color to RGB: HEX, RGB, HSL, and alpha formats

AuthorEditorial team 9-07-2026, 00:09 716
How to convert HEX color to RGB: HEX, RGB, HSL, and alpha formats
Advertising
In brief
  • HEX and RGB describe the same color differently: HEX is a hexadecimal representation #RRGGBB, RGB is three numbers from 0 to 255.
  • To convert HEX to RGB, break the code into three pairs and convert each from hexadecimal to decimal.
  • Transparency is added through the alpha channel: RGBA(…, 0.5) or an 8-digit HEX of the form #RRGGBBAA.
  • HSL (hue, saturation, lightness) is more convenient for manually adjusting shades and creating palettes.

The same color in layout can be written in several ways, which confuses beginners: the designer sent #3498DB, while the CSS layout specifies rgb(52, 152, 219) — is this an error or the same thing? The same thing. HEX and RGB are just two forms of representing the same color, like '1/2' and '0.5'. In this article, we will explore how HEX, RGB, and HSL formats work, how to quickly convert them to each other manually and in code, and when each format is more convenient to use in CSS and design.

HEX↔RGB Color Converter
Translate colors between HEX, RGB, and HSL — for free
Open converter →

What is RGB and why 255

RGB stands for Red, Green, Blue. The screen creates any color by mixing these three channels. Each channel is represented by a number from 0 to 255: 0 means the channel is off, 255 means it is at maximum brightness. Why 255? Because each channel is allocated 8 bits, and 8 bits provide 2⁸ = 256 values, which means from 0 to 255. Three channels with 256 gradations give 256³ ≈ 16.7 million colors.

Examples: rgb(255, 0, 0) — pure red, rgb(0, 255, 0) — green, rgb(0, 0, 0) — black, rgb(255, 255, 255) — white. Gray is equal values of all three channels, for example rgb(128, 128, 128).

What is HEX and how is it related to RGB

HEX is the same three RGB numbers, but written in hexadecimal (base 16) format and concatenated, with a hash symbol in front. Format: #RRGGBB, where RR is red, GG is green, BB is blue. The hexadecimal system uses digits 0–9 and letters A–F (A=10, B=11, … F=15). One pair of characters encodes a number from 00 to FF, which means exactly from 0 to 255 — therefore HEX and RGB are interchangeable.

There is also a short notation of three characters, for example #39F. It expands by doubling each character: #39F = #3399FF. This only works when both digits in the pair are the same.

How to convert HEX to RGB manually

Let's take #3498DB and break it into three pairs: 34, 98, DB. Each pair is converted from hexadecimal to decimal using the formula 'first character × 16 + second character':

34 → 3×16 + 4 = 52
98 → 9×16 + 8 = 152
DB → 13×16 + 11 = 219

Result: #3498DB = rgb(52, 152, 219) — a pleasant 'sky blue'. The reverse conversion from RGB to HEX: divide each number by 16 (the integer part is the first symbol, the remainder is the second). 52 = 3 remainder 4 → 34. If the number is less than 16, a zero is added on the left, for example 5 → 05.

Transparency: RGBA and 8-digit HEX

To make a color semi-transparent, an alpha channel is added — the degree of opacity from 0 (completely transparent) to 1 (completely opaque). In RGB, this is done through RGBA: rgba(52, 152, 219, 0.5) — the same blue, but visible at 50%. This is essential for shadows, overlays, and backgrounds under text.

HEX also has a version with transparency — 8 characters #RRGGBBAA, where the last pair encodes the alpha from 00 to FF. For example, #3498DB80 is approximately equal to 50% transparency (80 in hexadecimal ≈ 128 out of 255). Modern browsers understand this format, but for readability, many developers prefer RGBA.

HSL: when it's more convenient

HSL (Hue, Saturation, Lightness) describes color closer to human logic. Hue is the angle on the color wheel from 0 to 360° (0 is red, 120 is green, 240 is blue). Saturation is the intensity in percentage, Lightness is the brightness in percentage. Our #3498DB in HSL is approximately hsl(204, 70%, 53%).

The main advantage of HSL is that it is convenient for building palettes: to get a lighter or darker shade, you only need to change Lightness without touching the hue. For generating gradients, button states (hover, active), and themes, this is much clearer than randomly picking HEX.

What and where to apply in practice

HEX is the de facto standard in layouts and design systems: compact and familiar. RGB and especially RGBA are needed when transparency is required. HSL is used for programmatic color generation and fine-tuning palettes. All three formats are valid in CSS, and the browser will render them the same way — choose the one that is more convenient for the specific task. For one-time conversion, it is easiest to use an online converter to avoid calculating hexadecimal pairs in your head.

Frequently Asked Questions

What is the difference between HEX and RGB?
Essentially, there is no difference — they are two forms of representing the same color. HEX uses a hexadecimal notation #RRGGBB, while RGB uses three decimal numbers from 0 to 255. One HEX pair (00–FF) is exactly equal to one RGB number (0–255).

How to convert HEX to RGB manually?
Break the code into three pairs of characters (RR, GG, BB) and convert each from hexadecimal to decimal using the formula 'first character × 16 + second character'. For example, #3498DB → 52, 152, 219.

How to add transparency to a color?
Use the alpha channel: in RGBA format — the fourth value from 0 to 1, for example rgba(52,152,219,0.5). In HEX — an eight-digit representation #RRGGBBAA, where the last pair sets the opacity from 00 to FF.

What is better to use in CSS — HEX, RGB, or HSL?
All three work the same. HEX is compact and convenient for layouts, RGBA is needed for transparency, HSL is more convenient for generating palettes and selecting shades, as it allows you to change only lightness or saturation.

HEX↔RGB Color Converter
Translate colors between HEX, RGB, and HSL — for free
Open converter →

Updated: July 9, 2026. Edition of MegaInet.art.

How useful is the material?Evaluation helps us choose topics
00 ratings

Discussion

No one has spoken yet — be the first.

Comments are written by participants Log in to the site — it's free and takes a minute. Comments are moderated.
Log in
Advertising