Turn a hex color into a CSS rgba() string
The Hex to CSS rgba() String Converter takes a hex color and an opacity and produces a copy-ready CSS color string. It outputs the classic comma-separated rgba() form, a plain rgb() form, and the modern CSS Color 4 slash-alpha syntax, with a live swatch over a transparency checkerboard so you can judge the alpha at a glance.
How it works
A hex color packs three 8-bit channels into base 16. The converter splits the string into pairs and parses each pair as a 0–255 value:
#3366ff -> r = 0x33 = 51, g = 0x66 = 102, b = 0xff = 255
Shorthand 3-digit and 4-digit hex are expanded by doubling each digit (#36f becomes #3366ff). If the hex carries an eighth-digit alpha byte, that byte is divided by 255 to get a base alpha. The opacity percentage you enter is converted to a 0–1 fraction and multiplied with the base alpha, producing the final alpha channel used in the rgba() string.
Which output format to use
| Format | Example output | When to use |
|---|---|---|
rgba() | rgba(51, 102, 255, 0.8) | Maximum browser compatibility, CSS 2.1+ |
rgb() with alpha | rgb(51, 102, 255, 0.8) | Modern browsers; CSS spec allows alpha in rgb() |
| CSS Color 4 slash | rgb(51 102 255 / 80%) | Clean and readable; all current browsers |
Worked examples
Example 1 — standard hex with opacity:
Entering #3366ff at 80 percent opacity yields:
rgba(51, 102, 255, 0.8)— copy this for almost all projectsrgb(51 102 255 / 80%)— the modern equivalent
Example 2 — 8-digit hex with a second opacity:
If you have #3366ff80 (which already encodes 50% alpha in its eighth pair) and you set opacity to 50%, the combined alpha is 0.5 × 0.5 = 0.25, giving rgba(51, 102, 255, 0.25). This is useful when you receive a branded color with a built-in transparency from a design tool like Figma.
Example 3 — shorthand expansion:
#f0a expands to #ff00aa → rgba(255, 0, 170, 1).
Practical tips
- Design-to-code handoff: Figma and Sketch export colors as hex. Paste the hex here to get an immediately usable CSS value with a custom opacity.
- Overlays and modals: Semi-transparent dark overlays are typically
rgba(0, 0, 0, 0.5)— enter#000000at 50%. - Check on a checkerboard: The live swatch shows the color as it really appears over a transparent background, not composited over white, so you can judge low-alpha colors accurately.
- Tailwind and CSS variables: The CSS Color 4 slash form pairs cleanly with CSS custom properties:
--brand: 51 102 255; color: rgb(var(--brand) / 80%);
Notes
For maximum browser support the comma rgba() form is the safest choice; the space-and-slash form is cleaner but newer. Alpha is rounded to three decimal places and trailing zeros are trimmed so the output stays tidy. Everything runs in your browser — no color data is uploaded.