Skip to content

RGB to HEX converter

Type an RGB value to get its HEX code, or a HEX code to get its RGB value: both fields convert as you type. Each channel from 0 to 255 becomes two hexadecimal digits, so rgb(59 130 246) is #3b82f6, and an alpha of 0.5 adds 80 for #3b82f680. You can paste rgb(), rgba(), hsl(), three bare numbers or a 3, 4, 6 or 8-digit hex code, and copy the result in modern or legacy syntax. Working in OKLCH? Use the OKLCH to HEX converter.

#3b82f6, #38f or #3b82f680 with alpha.
rgb(59 130 246), rgba(59, 130, 246, 0.5), 59, 130, 246 or hsl().
Channels
Your color#3b82f6rgb(59 130 246)
HEX#3b82f6
HEX + alpha#3b82f6ff
rgb()rgb(59 130 246)
rgb() legacyrgb(59, 130, 246)
HSLhsl(217.2 91.2% 59.8%)
Closest Tailwind 4 colorΔE 1.9 · Practically identical · five closest

How RGB to HEX works

Hex is base 16, so two digits hold 16 × 16 = 256 values, exactly the 0 to 255 of one RGB channel. Divide by 16: the whole number is the first digit, the remainder the second. Alpha is scaled from 0–1 to 0–255 first and rounded.

For rgb(59 130 246): 59 = 3 × 16 + 11 → 3B, 130 = 8 × 16 + 2 → 82, 246 = 15 × 16 + 6 → F6. Together that is #3b82f6, the closest Tailwind 4 color to which is blue-500 (ΔE 1.9).

Channel÷ 16Hex
00 rest 000
593 rest 113B
1288 rest 080
20012 rest 8C8
25515 rest 15FF
Alpha× 255Hex
1255FF
0.75191BF
0.512880
0.256440
0.1261A
0000

HEX to RGB, and 8-digit hex support

Going back, read the code in pairs. #0f172acc is 0F, 17, 2A and CC: 0 × 16 + 15 = 15, 1 × 16 + 7 = 23, 2 × 16 + 10 = 42, and CC = 204, which is an alpha of 204 ÷ 255 = 0.8. In CSS that is rgb(15 23 42 / 0.8), or rgba(15, 23, 42, 0.8) in the older syntax.

Eight-digit (#rrggbbaa) and four-digit (#rgba) hex colors are defined in CSS Color Module Level 4. They work in Chrome 62, Firefox 49, Safari 10 and Edge 79 and later, so every current browser reads them; Internet Explorer never did. If a tool or email client you paste into does not, copy the rgba() line instead, which has the same color.

Hex holds whole numbers only, so a decimal channel is rounded: rgb(59.6 130 246) becomes 60, or 3C. Alpha is rounded to the nearest of 256 steps, so 0.5 and 0.502 both become 80. Need to know if text in this color is readable? Check it with the color contrast checker.

Blocks to try your colors on

9 of 127 free, no account. All of them in UI Pro.

  • Hero (hero-01)01

    Hero

    hero-01 · Free. Journey-planner hero: from/to card with leave-at tabs, a day-out photo card and four quick-task tiles.

    Open hero-01
  • Call to action (call-to-action-01)02

    Call to action

    call-to-action-01 · Free. Closing panel with a very large centred title, three pill actions (call, mail, book) and the founders' faces.

    Open call-to-action-01
  • 03

    All free blocks

    Every one with a live preview, filtered to the ones you can use for free first.

    See them all

Questions

How do I convert RGB to HEX?

Write each of the three channels (0 to 255) as a two-digit hexadecimal number and join them after a #. Divide the value by 16: the whole part is the first digit and the remainder the second, with 10 to 15 written as A to F. So 59 is 3 × 16 + 11, which is 3B, and rgb(59 130 246) is #3b82f6. Type the rgb() value above and the converter does it for you.

How do I convert HEX to RGB?

Split the code into pairs and read each pair as a number from 0 to 255: the first digit times 16 plus the second. #3b82f6 is 3B, 82 and F6, which is rgb(59 130 246). A three-digit code doubles each digit first, so #38f is #3388ff. Paste the hex code in the HEX field above to get rgb(), rgba() and HSL.

What is an 8-digit hex color?

The last two digits are the alpha (opacity), from 00 (fully transparent) to FF (opaque). The alpha 0 to 1 is multiplied by 255 and rounded, so 0.5 becomes 128, written 80: #3b82f680 is the same color as rgb(59 130 246 / 0.5). A four-digit code such as #38f8 is the short form. Both come from CSS Color Module Level 4.

What is the difference between rgb() and rgba()?

None in current CSS. CSS Color Module Level 4 made rgba() an alias of rgb(), and both accept an alpha. The newer syntax uses spaces and a slash, rgb(59 130 246 / 0.5); the older one uses commas, rgba(59, 130, 246, 0.5). The converter writes both, so you can match the style your codebase already uses.

How do I convert HSL to HEX?

Paste the hsl() or hsla() value into the RGB field. It is read as a color, so you get the hex code, rgb() and the closest Tailwind color the same way. For OKLCH, which Tailwind CSS 4 and shadcn/ui use, use the OKLCH to HEX converter.

Can I convert every color in a stylesheet at once?

Yes. Switch to "A list or CSS" and paste your CSS or a list of values, one per line. Every rgb(), rgba(), hsl() and hsla() becomes hex, so #0f172acc replaces rgba(15, 23, 42, 0.8), and everything else stays as it is. The other direction turns every hex code into rgb() and skips ID selectors and url(#id).

Is it free?

Yes. No sign-up, and nothing leaves your browser: the conversion runs on your own device. The address bar holds the current color, so you can share a link to it.

UI Pro

Build your next site from finished blocks

Every block, page template and website theme from €199, paid once, with every update and everything we add later. Not ready? The free blocks are open to everyone.

blocks
1401
page templates
55
website themes
29
The About page template from UI Pro, built from its blocks.

This card is a UI Pro block: Rooilijn (call-to-action-07).