HEX to RGB Converter
Convert HEX color codes to RGB, RGBA, HSL and HSLA instantly. Type or paste any HEX value — 3-digit, 6-digit or 8-digit with alpha. Get CSS-ready output, CSS variables and a WCAG contrast check against white and black. Everything runs in your browser.
Color Picker
Related Tools
Frequently Asked Questions
How do I convert HEX to RGB manually?▾
Split the 6-digit HEX code into three pairs and convert each from base-16 to base-10:
#3b82f6 → R: 3b = 59, G: 82 = 130, B: f6 = 246 → rgb(59, 130, 246)
For 3-digit shorthand (#39f), double each digit first: #3399ff, then convert.
For 8-digit HEX with alpha (#3b82f6cc), the last two digits are the alpha channel: cc = 204 → alpha = 204 / 255 ≈ 0.8.
What is the difference between HEX and RGB color formats?▾
HEX (#3b82f6) and RGB (rgb(59, 130, 246)) represent exactly the same color — they are just different notations for the same value.
HEX is compact and the most common format in CSS, design tools, and HTML. RGB is more readable for humans and easier to manipulate programmatically. Both are valid in CSS and supported by all browsers.
Use HEX for static colors in stylesheets. Use RGB when you need to adjust channels in code, or when using CSS calc() or JavaScript to generate dynamic colors.
How do I convert HEX to RGBA (with transparency)?▾
To add transparency to a HEX color in CSS you have two options:
1. Use rgba(): rgba(59, 130, 246, 0.5) — the fourth value is opacity from 0 (transparent) to 1 (opaque). 2. Use 8-digit HEX: #3b82f680 — the last two hex digits represent alpha (00 = transparent, ff = opaque). 80 in hex = 128 in decimal = 128/255 ≈ 0.5 opacity.
Our tool shows both RGBA and HSLA formats with alpha channel support.
How do I convert HEX to RGB in JavaScript?▾
const hexToRgb = (hex) => { const clean = hex.replace('#', ''); const full = clean.length === 3 ? clean.split('').map(c => c + c).join('') : clean; const n = parseInt(full, 16); return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 }; };
hexToRgb('#3b82f6'); // { r: 59, g: 130, b: 246 }
Why do some HEX colors use 3 digits and others use 6?▾
3-digit HEX is a shorthand where each digit is doubled: #39f is equivalent to #3399ff. It only works when both digits of each color channel are identical.
3-digit HEX reduces file size slightly but only applies to a subset of colors. 6-digit HEX can represent all 16,777,216 possible RGB colors. 8-digit HEX (#RRGGBBAA) adds an alpha channel for transparency, supported in all modern browsers.