A HEX color code is a six-character alphanumeric string used in web design and digital graphics to represent a specific color. The format follows the pattern #RRGGBB, where each two-character pair encodes the intensity of one of the three additive primary colors — red (RR), green (GG), and blue (BB) — using hexadecimal notation (base 16). Each pair ranges from 00 (zero intensity) to FF (maximum intensity, equivalent to 255 in decimal).
HEX codes originated from the need to define colors in HTML and CSS without relying on named color keywords. While CSS now supports multiple color formats including rgb(), hsl(), and oklch(), HEX remains the most widely used notation in front-end development, design handoffs, and branding guidelines. Virtually every color picker in tools like Figma, Sketch, Adobe Photoshop, and Canva displays a HEX value by default.
The total number of unique colors representable with six-digit HEX codes is 16,777,216 (256 × 256 × 256). This is often referred to as "True Color" or "24-bit color," which matches the color depth of most modern displays. Each channel gets 8 bits (one byte), and three channels together produce 24 bits of color data.
HEX codes are case-insensitive, so #ff8000 and #FF8000 refer to the same color. Some style guides prefer uppercase for readability, while CSS minifiers often output lowercase to save bytes — though in practice the difference is negligible.
Converting a HEX color code to its RGB equivalent is straightforward. The process involves splitting the six-character string into three pairs and converting each pair from hexadecimal (base 16) to decimal (base 10). Here is the step-by-step method:
#, strip it. For example, #1A2B3C becomes 1A2B3C.1A, 2B, 3C.1A → (1 × 16) + 10 = 262B → (2 × 16) + 11 = 433C → (3 × 16) + 12 = 60rgb(26, 43, 60).The hexadecimal digits and their decimal equivalents are: 0=0, 1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9, A=10, B=11, C=12, D=13, E=14, F=15. Memorizing A through F is the only part that differs from standard decimal arithmetic.
For programmatic conversion, most languages offer built-in functions. In JavaScript, parseInt("1A", 16) returns 26. In Python, int("1A", 16) does the same. CSS itself handles both formats natively, so conversion is primarily useful when you need to manipulate individual color channels in code — for instance, adjusting brightness, creating gradients programmatically, or blending two colors.
CSS supports a shorthand 3-digit HEX format (#RGB) as a convenience when each of the three pairs consists of identical digits. In this shorthand, each single digit is expanded by doubling it. For example:
#F80 expands to #FF8800 → rgb(255, 136, 0)#FFF expands to #FFFFFF → rgb(255, 255, 255)#000 expands to #000000 → rgb(0, 0, 0)#09C expands to #0099CC → rgb(0, 153, 204)#A3F expands to #AA33FF → rgb(170, 51, 255)The 3-digit notation reduces the number of available colors from 16.7 million to just 4,096 (16 × 16 × 16), so it cannot represent every color. It is most commonly used for simple or well-known colors in CSS files where brevity is valued.
CSS also supports 4-digit (#RGBA) and 8-digit (#RRGGBBAA) HEX codes that include an alpha (transparency) channel. The alpha value follows the same hexadecimal logic: FF is fully opaque and 00 is fully transparent. For example, #FF880080 represents the color rgb(255, 136, 0) at 50% opacity. Our converter focuses on the standard 3- and 6-digit formats; if you enter a code with an alpha channel, it will process only the RGB portion.
Below is a reference table of common HEX colors and their RGB equivalents. This table covers the most frequently used colors in web design, CSS named colors, and popular brand palette choices.
| Color Name | HEX | R | G | B | CSS Usage |
|---|---|---|---|---|---|
| Black | #000000 | 0 | 0 | 0 | Text, borders |
| White | #FFFFFF | 255 | 255 | 255 | Backgrounds |
| Red | #FF0000 | 255 | 0 | 0 | Errors, alerts |
| Green | #00FF00 | 0 | 255 | 0 | Success states |
| Blue | #0000FF | 0 | 0 | 255 | Links, primary |
| Yellow | #FFFF00 | 255 | 255 | 0 | Warnings |
| Cyan | #00FFFF | 0 | 255 | 255 | Accent, info |
| Magenta | #FF00FF | 255 | 0 | 255 | Creative, bold |
| Gray | #808080 | 128 | 128 | 128 | Muted text |
| Silver | #C0C0C0 | 192 | 192 | 192 | Borders, subtle |
| Maroon | #800000 | 128 | 0 | 0 | Dark accents |
| Navy | #000080 | 0 | 0 | 128 | Headers, nav |
| Teal | #008080 | 0 | 128 | 128 | Accent |
| Olive | #808000 | 128 | 128 | 0 | Earthy palettes |
| Orange | #FFA500 | 255 | 165 | 0 | CTAs, buttons |
| Coral | #FF7F50 | 255 | 127 | 80 | Warm accents |
| Tomato | #FF6347 | 255 | 99 | 71 | Alerts, badges |
| Gold | #FFD700 | 255 | 215 | 0 | Highlights |
| SkyBlue | #87CEEB | 135 | 206 | 235 | Backgrounds |
| SlateGray | #708090 | 112 | 128 | 144 | Dark UI |
CSS defines 147 named colors in total, each with a corresponding HEX value. While named colors are convenient for prototyping, professional projects typically rely on HEX or RGB values for precision and consistency across browsers and design tools.
Developers and designers frequently need the exact HEX and RGB values of popular brand colors for mockups, integrations, and style guides. Below is a quick reference for some of the most commonly requested brand colors:
| Brand | HEX | RGB |
|---|---|---|
| Facebook Blue | #1877F2 | rgb(24, 119, 242) |
| Twitter / X Black | #000000 | rgb(0, 0, 0) |
| YouTube Red | #FF0000 | rgb(255, 0, 0) |
| Spotify Green | #1DB954 | rgb(29, 185, 84) |
| Instagram Gradient Start | #F58529 | rgb(245, 133, 41) |
| LinkedIn Blue | #0A66C2 | rgb(10, 102, 194) |
| Slack Purple | #4A154B | rgb(74, 21, 75) |
| WhatsApp Green | #25D366 | rgb(37, 211, 102) |
| TikTok Aqua | #69C9D0 | rgb(105, 201, 208) |
| Pinterest Red | #E60023 | rgb(230, 0, 35) |
Brand guidelines often specify colors in multiple formats (HEX, RGB, CMYK, Pantone). When implementing brand colors in CSS, always confirm values against the official brand resource page to ensure accuracy. Colors can shift slightly between screens, so consistency in code is essential.
Understanding when to use each color model helps you work more efficiently across different tools and media:
| Model | Format | Range | Best For |
|---|---|---|---|
| HEX | #RRGGBB | 00–FF per channel | CSS shorthand, design specs |
| RGB | rgb(R, G, B) | 0–255 per channel | Programmatic manipulation, JS canvas |
| HSL | hsl(H, S%, L%) | H: 0–360, S/L: 0–100% | Creating harmonious palettes, theming |
| CMYK | C, M, Y, K percentages | 0–100% per channel | Print design, offset printing |
| OKLCH | oklch(L C H) | L: 0–1, C: 0–0.4, H: 0–360 | Perceptually uniform color, modern CSS |
HEX and RGB are mathematically identical — they represent the same color space using different notation. Converting between them is a simple base-16 to base-10 translation with no loss of precision or gamut differences. HSL, on the other hand, is a transformation of RGB into a cylindrical coordinate system that makes it easier to reason about hue, saturation, and lightness independently. CMYK is a subtractive color model used in printing and cannot represent all RGB colors (and vice versa), so conversions between RGB and CMYK are approximate.
In modern CSS (Level 4), the color() function and new color spaces like oklch() and display-p3 are gaining adoption, especially for wide-gamut displays. However, HEX and RGB remain the baseline for web compatibility and are supported by every browser in use today.
Both HEX and RGB values are valid in CSS and produce identical results. Here are practical examples of how each format is used:
CSS declarations:
/* HEX notation */
body { background-color: #1A2B3C; }
/* RGB notation */
body { background-color: rgb(26, 43, 60); }
/* RGB with alpha (transparency) */
.overlay { background-color: rgba(26, 43, 60, 0.5); }
/* Modern CSS — space-separated syntax */
.card { color: rgb(26 43 60 / 80%); }
JavaScript conversion functions:
// HEX to RGB
function hexToRgb(hex) {
const h = hex.replace('#', '');
return {
r: parseInt(h.substring(0, 2), 16),
g: parseInt(h.substring(2, 4), 16),
b: parseInt(h.substring(4, 6), 16)
};
}
// RGB to HEX
function rgbToHex(r, g, b) {
return '#' + [r, g, b]
.map(v => v.toString(16).padStart(2, '0'))
.join('').toUpperCase();
}
When working with the HTML Canvas API, colors must often be set as strings. Both "#FF8000" and "rgb(255, 128, 0)" work for fillStyle and strokeStyle. However, the getImageData() method returns pixel data as an array of 0–255 integers (RGBA), making RGB the natural format for pixel-level manipulation.
In CSS custom properties (variables), HEX values are commonly stored for simplicity:
:root {
--primary: #4A90E2;
--primary-rgb: 74, 144, 226; /* for use with rgba() */
}
.element {
background: rgba(var(--primary-rgb), 0.3);
}
This pattern of storing raw RGB channel values as a CSS variable is a popular technique that allows you to apply opacity dynamically without converting between formats at runtime.
Converting HEX to RGB is often the first step in calculating color contrast ratios for accessibility compliance. The Web Content Accessibility Guidelines (WCAG) require a minimum contrast ratio of 4.5:1 for normal text and 3:1 for large text (18px+ bold or 24px+ regular).
The contrast ratio formula requires the relative luminance of each color, which is computed from linear RGB values. The steps are:
As you can see, the RGB values are the essential input to every accessibility contrast calculation. Tools like the WebAIM Contrast Checker, Chrome DevTools color picker, and axe accessibility scanner all perform this conversion internally.
For designers, a quick rule of thumb: dark text on a light background (or vice versa) with a luminance difference of at least 125 and a color difference of at least 500 (using the sum of absolute differences across R, G, B channels) will generally pass WCAG AA standards.
Split the 6-digit HEX code into three pairs (RR, GG, BB) and convert each pair from base 16 to base 10. For example, #1A2B3C becomes R = 26, G = 43, B = 60, which is written as rgb(26, 43, 60). Each hexadecimal digit A–F represents values 10–15.
#FF5733 converts to rgb(255, 87, 51). This is a vibrant red-orange color commonly used for call-to-action buttons and warning elements in web design.
A valid HEX color code consists of a # symbol followed by exactly 6 hexadecimal characters (digits 0–9 and letters A–F). Shorthand 3-digit codes like #FFF are also valid. CSS additionally supports 4-digit and 8-digit HEX codes that include an alpha (transparency) channel.
HEX and RGB represent the same color space — they are different notations for the same data. HEX uses base-16 encoding (#4A90E2) while RGB uses decimal values (rgb(74, 144, 226)). Converting between them involves no loss of quality or color information; it is purely a change of notation.
Yes. CSS supports 8-digit HEX codes where the last two digits represent the alpha channel. For example, #FF880080 is orange at 50% opacity. You can also use rgba() for transparency: rgba(255, 136, 0, 0.5). The 8-digit HEX format is supported in all modern browsers.
Expand each digit by doubling it. #F80 becomes #FF8800, which then converts to rgb(255, 136, 0). The shorthand only works when each pair in the full code would consist of two identical characters.
#000000 converts to rgb(0, 0, 0), which is pure black. All three color channels are at zero intensity, meaning no light is emitted. In CSS, this is equivalent to the named color black.
#FFFFFF converts to rgb(255, 255, 255), which is pure white. All three color channels are at maximum intensity. In CSS, this equals the named color white.
HEX codes are more compact (7 characters including the hash vs. up to 16 characters for an RGB declaration), making them convenient for design specs, style guides, and quick copy-paste workflows. They are also the default output format in most design tools like Figma, Sketch, and Photoshop. RGB is preferred when you need to manipulate individual channels programmatically.
First convert both your text color and background color from HEX to RGB. Then calculate the relative luminance of each using the WCAG formula, and compute the contrast ratio. WCAG AA requires at least 4.5:1 for normal text and 3:1 for large text. Tools like WebAIM Contrast Checker automate this process.