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#FFFFFFFFHEX 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:
For the alpha channel, first multiply the 0-1 value by 255, then convert the result to hex:
Worked Example: rgba(255, 128, 0, 0.5)
1. Convert each RGB channel:
- R:
- G:
- B:
2. Convert alpha channel:
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:
| Color | RGBA | Hex | 8-digit Hex |
|---|---|---|---|
| White | rgba(255,255,255,1) | #FFFFFF | #FFFFFFFF |
| Black | rgba(0,0,0,1) | #000000 | #000000FF |
| Red | rgba(255,0,0,1) | #FF0000 | #FF0000FF |
| Red 50% | rgba(255,0,0,0.5) | — | #FF000080 |
| Green | rgba(0,128,0,1) | #008000 | #008000FF |
| Blue | rgba(0,0,255,1) | #0000FF | #0000FFFF |
| Blue 50% | rgba(0,0,255,0.5) | — | #0000FF80 |
| Yellow | rgba(255,255,0,1) | #FFFF00 | #FFFF00FF |
| Cyan | rgba(0,255,255,1) | #00FFFF | #00FFFFFF |
| Magenta | rgba(255,0,255,1) | #FF00FF | #FF00FFFF |
| Orange | rgba(255,165,0,1) | #FFA500 | #FFA500FF |
| Purple | rgba(128,0,128,1) | #800080 | #800080FF |
| Gray | rgba(128,128,128,1) | #808080 | #808080FF |
| Navy | rgba(0,0,128,1) | #000080 | #000080FF |
| Coral | rgba(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
| Opacity | Alpha (0-1) | Decimal (0-255) | Hex |
|---|---|---|---|
| 100% | 1.0 | 255 | FF |
| 75% | 0.75 | 191 | BF |
| 50% | 0.5 | 128 | 80 |
| 25% | 0.25 | 64 | 40 |
| 10% | 0.1 | 26 | 1A |
| 0% | 0.0 | 0 | 00 |
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
| Feature | RGBA | Hex |
|---|---|---|
| Notation | Decimal (0-255) | Hexadecimal (00-FF) |
| Alpha support | Built-in (0-1) | 8-digit format (#RRGGBBAA) |
| Readability | More human-readable | More compact |
| CSS syntax | rgba(255, 0, 0, 0.5) | #FF000080 |
| Programmatic use | Easier to manipulate values | Easier for string comparison |
| Design tools | Used in some color pickers | Standard 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:
| Format | Syntax Example | Alpha | Best For |
|---|---|---|---|
| HEX | #FF0000 | 8-digit only | Compact CSS, design tools |
| RGB | rgb(255, 0, 0) | No | Programmatic manipulation |
| RGBA | rgba(255, 0, 0, 0.5) | Yes (0-1) | Overlays, transparency effects |
| HSL | hsl(0, 100%, 50%) | No | Intuitive color selection |
| HSLA | hsla(0, 100%, 50%, 0.5) | Yes (0-1) | Theme variations, palettes |
| OKLCH | oklch(0.63 0.26 29) | Yes (/ 0.5) | Perceptually uniform colors |
Related Tools
- Hex to Binary Converter — Convert hexadecimal values to binary representation