RGBA 转 HEX 转换器

这个 RGBA 转 HEX 转换器可将 RGBA 颜色值(红、绿、蓝、透明度)转换为十六进制颜色代码。输入 RGBA 值,即可获取 6 位或 8 位(含透明度)十六进制代码,带有实时颜色预览。

RGBA to HEX Converter

Convert RGBA color values to hexadecimal (HEX) format with alpha channel support. Perfect for web development and design tasks.

rgba(255, 255, 255, 1)
#FFFFFF
#FFFFFFFF

HEX to RGBA

Enter a hex color code to convert it back to RGBA values.

Frequently Asked Questions

什么是RGBA颜色格式?

RGBA代表红(Red)、绿(Green)、蓝(Blue)、透明度(Alpha)。每个颜色通道(R、G、B)的值范围为0-255,而透明度通道控制不透明度,从0(完全透明)到1(完全不透明)。例如,rgba(255, 0, 0, 0.5)是半透明的红色。

如何将RGBA转换为十六进制?

将每个R、G、B值从十进制转换为十六进制:除以16,商是第一个十六进制数字,余数是第二个。对于透明度通道,乘以255,然后转换为十六进制。例如,rgba(255, 128, 0, 0.5):R=FF,G=80,B=00,A=80,得到#FF800080。

什么是8位十六进制颜色?

标准十六进制颜色使用6位(#RRGGBB)表示红、绿、蓝通道。8位十六进制(#RRGGBBAA)添加两位表示透明度通道,支持不使用rgba()函数的透明效果。例如,#FF000080是50%不透明度的红色。

rgba(255,0,0,0.5)的十六进制是什么?

rgba(255,0,0,0.5)以8位十六进制格式转换为#FF000080。红色通道(255)变为FF,绿色(0)变为00,蓝色(0)变为00,透明度(0.5)变为80(十进制128,即255的50%)。

所有浏览器都支持8位十六进制颜色吗?

是的,所有现代浏览器都支持8位十六进制颜色(#RRGGBBAA),这是CSS Color Level 4规范的一部分。包括Chrome 62+、Firefox 49+、Safari 10+和Edge 79+。对于旧版浏览器支持,请改用rgba()函数。

RGBA和HSLA有什么区别?

RGBA使用红、绿、蓝通道(0-255)加透明度来定义颜色。HSLA使用色相(0-360°)、饱和度(0-100%)、亮度(0-100%)加透明度。HSLA对于选择颜色变体(更亮、更暗、更饱和)更直观,而RGBA直接映射到屏幕的显示方式。

十六进制中透明度如何工作?

在8位十六进制格式中,最后两位代表透明度通道。00=完全透明,FF=完全不透明。常见值:80≈50%不透明度,BF≈75%,40≈25%。转换公式为:hex_alpha = Math.round(alpha * 255).toString(16)。

十六进制和RGB有什么区别?

十六进制(#FF0000)和RGB(rgb(255,0,0))表示相同的颜色,只是使用不同的表示方法。十六进制使用16进制数字,RGB使用0-255的十进制值。它们对任何颜色都是可互换的。十六进制在CSS代码中更紧凑,而RGB更易于以编程方式阅读和操作。

How to Convert RGBA to Hex

Converting RGBA to hexadecimal involves translating each color channel from decimal (base-10) to hexadecimal (base-16) notation. The formula for each channel is:

Hex digit 1=value÷16\text{Hex digit 1} = \lfloor \text{value} \div 16 \rfloor
Hex digit 2=valuemod16\text{Hex digit 2} = \text{value} \mod 16

For the alpha channel, first multiply the 0-1 value by 255, then convert the result to hex:

Alphahex=toHex(Math.round(α×255))\text{Alpha}_{hex} = \text{toHex}(\text{Math.round}(\alpha \times 255))

Worked Example: rgba(255, 128, 0, 0.5)

1. Convert each RGB channel:

  • R: 255÷16=15 remainder 15FF255 \div 16 = 15 \text{ remainder } 15 \Rightarrow \text{FF}
  • G: 128÷16=8 remainder 080128 \div 16 = 8 \text{ remainder } 0 \Rightarrow \text{80}
  • B: 0÷16=0 remainder 0000 \div 16 = 0 \text{ remainder } 0 \Rightarrow \text{00}

2. Convert alpha channel:

  • 0.5×255=127.51280.5 \times 255 = 127.5 \approx 128
  • 128÷16=8 remainder 080128 \div 16 = 8 \text{ remainder } 0 \Rightarrow \text{80}

Result:

6-digit hex: #FF8000 (without alpha)

8-digit hex: #FF800080 (with alpha)

Common RGBA to Hex Conversions

Reference table for common colors with their RGBA values, 6-digit hex codes, and 8-digit hex codes:

ColorRGBAHex8-digit Hex
Whitergba(255,255,255,1)#FFFFFF#FFFFFFFF
Blackrgba(0,0,0,1)#000000#000000FF
Redrgba(255,0,0,1)#FF0000#FF0000FF
Red 50%rgba(255,0,0,0.5)#FF000080
Greenrgba(0,128,0,1)#008000#008000FF
Bluergba(0,0,255,1)#0000FF#0000FFFF
Blue 50%rgba(0,0,255,0.5)#0000FF80
Yellowrgba(255,255,0,1)#FFFF00#FFFF00FF
Cyanrgba(0,255,255,1)#00FFFF#00FFFFFF
Magentargba(255,0,255,1)#FF00FF#FF00FFFF
Orangergba(255,165,0,1)#FFA500#FFA500FF
Purplergba(128,0,128,1)#800080#800080FF
Grayrgba(128,128,128,1)#808080#808080FF
Navyrgba(0,0,128,1)#000080#000080FF
Coralrgba(255,127,80,1)#FF7F50#FF7F50FF

Understanding Alpha Channel in Hex

The 8-digit hex format (#RRGGBBAA) extends the standard 6-digit format by appending two hexadecimal digits for the alpha (transparency) channel. The alpha digits range from 00 (fully transparent) to FF (fully opaque).

Common Alpha Values

OpacityAlpha (0-1)Decimal (0-255)Hex
100%1.0255FF
75%0.75191BF
50%0.512880
25%0.256440
10%0.1261A
0%0.0000

The 8-digit hex format is part of the CSS Color Level 4 specification and is supported in all modern browsers. When the alpha value is FF (fully opaque), the 8-digit code is functionally identical to the 6-digit version. For example, #FF0000FF renders the same as #FF0000.

RGBA vs Hex: Key Differences

FeatureRGBAHex
NotationDecimal (0-255)Hexadecimal (00-FF)
Alpha supportBuilt-in (0-1)8-digit format (#RRGGBBAA)
ReadabilityMore human-readableMore compact
CSS syntaxrgba(255, 0, 0, 0.5)#FF000080
Programmatic useEasier to manipulate valuesEasier for string comparison
Design toolsUsed in some color pickersStandard in Figma, Sketch, etc.

CSS Color Formats Comparison

CSS supports multiple color formats, each with different strengths. Here is a comparison of the most commonly used formats:

FormatSyntax ExampleAlphaBest For
HEX#FF00008-digit onlyCompact CSS, design tools
RGBrgb(255, 0, 0)NoProgrammatic manipulation
RGBArgba(255, 0, 0, 0.5)Yes (0-1)Overlays, transparency effects
HSLhsl(0, 100%, 50%)NoIntuitive color selection
HSLAhsla(0, 100%, 50%, 0.5)Yes (0-1)Theme variations, palettes
OKLCHoklch(0.63 0.26 29)Yes (/ 0.5)Perceptually uniform colors

Related Tools