Skip to content
colors

hexAToRgba

The `hexAToRgba` function converts 4-digit or 8-digit HEX alpha colors into RGBA channel values.

1 min read85 words

Function Signature

js

hexAToRgba(hexA: string): { r: number, g: number, b: number, a: number }

Parameters

  • hexA (string): A HEX alpha color in #rgba or #rrggbbaa format.

Return Value

An object containing RGB channel values and alpha rounded to two decimals.

js

hexAToRgba("#00aaffcc");
// { r: 0, g: 170, b: 255, a: 0.8 }

hexAToRgba("#0afc");
// { r: 0, g: 170, b: 255, a: 0.8 }

Examples

js

console.log(hexAToRgba("#ff6600ff"));
// { r: 255, g: 102, b: 0, a: 1 }

console.log(hexAToRgba("#0000"));
// { r: 0, g: 0, b: 0, a: 0 }

Error Handling

Throws Invalid hexA color if the input is not valid 4-digit or 8-digit HEX alpha.

Usage Notes

  • Use rgbaToHexA for the reverse conversion.
  • The alpha channel is decoded from the final HEX byte.
  • For non-alpha HEX colors, use hexToRgb.

Previous

rgbToHex

Next

rgbaToHexA


Top tools

BoardlyLinksyChromoCodeHub

ReadyTools

CareersContactTools
Pricing7 days free
GuidesDocsBlogUpdatesLaraVault

Select Language

Set theme

© 2026 ReadyTools. All rights reserved.