Function Signature
js
rgbaToHexA(r: number, g: number, b: number, a?: number): stringParameters
r(number): Red channel value (0–255).g(number): Green channel value (0–255).b(number): Blue channel value (0–255).a(number, optional): Alpha value (0–1). Defaults to1(fully opaque).
Return Value
Returns an 8-digit HEX string (#rrggbbaa) where the last two characters encode the alpha channel.
js
rgbaToHexA(255, 102, 0, 1);
// "#ff6600ff"
rgbaToHexA(0, 170, 255, 0.5);
// "#00aaff80"
rgbaToHexA(0, 0, 0, 0);
// "#00000000"Examples
js
// Fully opaque green
console.log(rgbaToHexA(34, 139, 34));
// "#228b22ff"
// Semi-transparent blue
console.log(rgbaToHexA(0, 0, 255, 0.25));
// "#0000ff40"
// Transparent black
console.log(rgbaToHexA(0, 0, 0, 0));
// "#00000000"Error Handling
Values are automatically clamped: RGB is clamped between 0–255, and alpha is clamped between 0–1. Out-of-range values are adjusted silently.
Usage Notes
- Always outputs lowercase HEX strings.
- Useful for modern CSS and graphics APIs supporting 8-digit HEX.
- For HEX without alpha, use
rgbToHexinstead.