Skip to content
colors

rgbaToHexA

The `rgbaToHexA` function converts RGBA values into an 8-digit HEX color string (`#rrggbbaa`). It encodes the alpha channel as the last two hexadecimal digits.

1 min read121 words

Function Signature

js

rgbaToHexA(r: number, g: number, b: number, a?: number): string

Parameters

  • 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 to 1 (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 rgbToHex instead.

Previous

hexAToRgba

Next

hexToCmyk


Top-Werkzeuge

BoardlyLinksyChromoCodeHub

ReadyTools

KarriereKontaktWerkzeuge
Preise7 Tage gratis
AnleitungenDocsBlogUpdatesLaraVault

Sprache wählen

Thema wählen

© 2026 ReadyTools. Alle Rechte vorbehalten.