HEX Color Codes Explained: A Complete Guide

What Is a HEX Color Code?

A HEX color code is a six-digit hexadecimal number preceded by a hash symbol (#) that represents a color in web design and digital graphics. The six digits encode three color channels: red, green, and blue (RGB). Each channel uses two hexadecimal digits, giving 256 possible intensity levels (00 to FF) per channel and over 16.7 million possible color combinations.

HEX codes are the most widely used color notation in CSS, HTML, and graphic design software. Their compact format and universal support make them the default choice for specifying colors in web development.

Reading HEX Codes

The six digits break into three pairs: positions 1-2 control red, 3-4 control green, and 5-6 control blue. Higher values mean more of that color component.

When all three channels have equal values, the result is always a shade of gray. The higher the value, the lighter the gray.

Shorthand Notation

When each pair consists of repeated digits, CSS allows a three-digit shorthand. #FF6600 becomes #F60, #AABBCC becomes #ABC, and #000000 becomes #000. This shorthand only works when every pair has matching digits. #F08 expands to #FF0088, not #F00088.

Four-digit shorthand adds transparency: #F60A expands to #FF6600AA, where the last pair controls alpha (opacity). Eight-digit HEX codes provide full alpha specification: #FF660080 is the color #FF6600 at approximately 50% opacity.

How to Create Custom Colors

Understanding the channel structure lets you create colors intuitively. Want a warm orange? Start with high red (E or F), medium green (8-A), and low blue (0-3). Adjusting channels produces variations: increasing green lightens toward yellow, decreasing red darkens toward brown.

For grays, use identical values across all channels. For pure hues, set one or two channels high and the rest to zero. For pastel shades, use high values (C0-FF) across all channels with one slightly higher than the others. For dark, rich tones, use low-to-medium values (30-80) with one channel dominant.

Common Web Colors

Several HEX values appear frequently in web design:

Design systems typically define a palette of HEX codes for consistent use across a project. Tools like Figma, Sketch, and Adobe XD display and accept HEX codes natively.

HEX in CSS

CSS accepts HEX codes in property values: color, background-color, border-color, box-shadow, and any property that takes a color value. HEX codes are case-insensitive (#ff6600 and #FF6600 are identical) and can be used alongside other color formats in the same stylesheet.

Modern CSS also supports the newer color() function and color spaces beyond sRGB, but HEX codes remain the most universally understood and supported format.

Use the color tools on CalcHub to explore HEX colors, convert between formats, and build palettes, or check our CSS tools for design utilities.

Explore and convert HEX colors with CalcHub’s color tools.

Explore all free tools on CalcHub

Browse Tools