3 Digit HEX Code: What It Is, How It Works, Examples

July 15, 2026 5 min read Dharmeshkumar

If you’ve ever worked with HTML, CSS, or web design, you may have noticed color values like #FFF, #000, or #F00. At first glance, these look different from standard six-digit HEX color codes such as #FFFFFF or #FF0000. This often leads beginners to ask whether three-digit HEX codes are a different color format or simply a shorter version of the same thing.

The answer is simple: a 3 digit HEX code is a shorthand version of a six-digit HEX color code. Instead of writing six hexadecimal characters, you can write only three—but only when each pair of digits in the original color is identical. This shorthand makes CSS cleaner, easier to read, and slightly shorter without changing the final color displayed by the browser.

In this guide, you will learn what a 3-digit HEX code is, how it works, and when you should use it. Whether you are a beginner learning CSS or an experienced web developer, understanding shorthand HEX colors will help you write cleaner and better code.

What Is a 3 Digit HEX Code?

A 3 digit HEX code is a shortened form of a standard six-digit hexadecimal color code used in HTML and CSS. It represents the same color but uses only three hexadecimal characters instead of six.

A standard HEX color follows this format: #RRGGBB

A shorthand HEX color follows this format: #RGB

Each character in the shorthand version is automatically duplicated by the browser.

For example:

3-Digit HEX CodeExpanded 6-Digit HEX CodePreview
#FFF#FFFFFF
#000#000000
#F00#FF0000🟥
#0F0#00FF00🟩
#00F#0000FF🟦
#FF0#FFFF00🟨
#0FF#00FFFF🟦
#F0F#FF00FF🟪
#CCC#333333

Although these values look different, they produce exactly the same color on the screen.

Why Does a 3 Digit HEX Code Exist?

When CSS was introduced, developers often repeated the same color values throughout their stylesheets. Writing long six-digit HEX values again and again made the code larger and harder to read.

To simplify common color values, browsers introduced shorthand HEX notation. If every pair of hexadecimal digits is identical, the browser allows the color to be written using only three digits.

For example:

  • FFFFFF becomes #FFF
  • CCCCCC becomes #CCC
  • 999999 becomes #999

This small feature helps developers write cleaner code while keeping the final color exactly the same.

How Does a 3 Digit HEX Code Work?

Many beginners think a three-digit HEX color represents fewer colors than a six-digit HEX value. In reality, the browser simply expands the shorthand version before displaying it.

Here’s how it works:

Shorthand HEXExpanded 6-Digit HEX
#ABC#AABBCC
#123#112233
#DEF#DDEEFF
#789#778899
#F0A#FF00AA
#5C8#55CC88

The Expansion Rule

Each hexadecimal character is simply repeated once:

  • A becomes AA
  • B becomes BB
  • C becomes CC

For example:

  • ABC becomes #AABBCC
  • F0A becomes #FF00AA
  • 5C8 becomes #55CC88

This conversion happens automatically in all modern browsers, so a 3-digit HEX code and its expanded 6-digit version always produce the exact same color. The shorthand format is simply a shorter way to write certain HEX color values in HTML and CSS.

Using 3 Digit HEX Codes in HTML and CSS

Using shorthand HEX colors is exactly the same as using standard HEX values.

Example in CSS:

body{ background:#FFF; color:#333; } button{ background:#06C; color:#FFF; }

Example in HTML:

<p style="color:#F00;">This text appears red.</p>

The browser automatically converts these shorthand values into their equivalent six-digit HEX colors before rendering the page.

Browser Support for 3 Digit HEX Codes

One of the biggest advantages of using a 3 digit HEX code is its excellent browser compatibility. This shorthand color format has been supported by web browsers for many years and works reliably in all modern browsers, including Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, and Opera.

Because browsers automatically expand shorthand HEX values into their six-digit equivalents, you don’t need any extra CSS or JavaScript for them to work.

For example:

background: #FFF;

is automatically interpreted by the browser as:

background: #FFFFFF;

The same rule applies to every valid shorthand HEX color.

Can You Convert a 6 Digit HEX Code to a 3 Digit HEX Code?

Yes, but only when the six-digit HEX color follows the shorthand rule.

A six-digit HEX color can be converted into a three-digit version if each pair of characters contains the same value.

For example:

6-Digit HEX3-Digit HEX
#FFFFFF#FFF
#000000#000
#FF0000#F00
#00FF00#0F0
#0000FF#00F
#CCCCCC#CCC
#999999#999
#FFCC00#FC0

However, many HEX colors cannot be shortened.

Examples include:

  • #3498DB
  • #1ABC9C
  • #E74C3C
  • #2ECC71

Since these values don’t contain matching character pairs, they must remain in the standard six-digit format.

Should You Always Use a 3 Digit HEX Code?

Not necessarily.

While shorthand HEX colors make CSS slightly shorter, they’re only useful when the original color can actually be shortened. Modern websites often use custom brand colors, gradients, and design systems that require precise six-digit HEX values.

For small projects, personal websites, or simple user interfaces, shorthand HEX codes can make your CSS cleaner and easier to read.

For larger projects with design guidelines, using six-digit HEX values is often preferred because every color is written in a consistent format, making stylesheets easier to maintain.

The best approach is to use shorthand only when it improves readability without affecting consistency.

Best Use Cases for 3 Digit HEX Codes

Shorthand HEX colors are commonly used in situations where simple, standard colors are enough.

Some common examples include:

  • Setting a white page background with #FFF
  • Displaying black text using #000
  • Creating simple borders with #CCC
  • Styling headings with dark gray colors like #333
  • Building quick HTML or CSS prototypes
  • Learning web development and practicing CSS

For projects that rely on exact brand colors or custom UI themes, six-digit HEX values usually provide greater flexibility.

Conclusion

A 3 digit HEX code is a convenient shorthand for certain six-digit HEX color codes. Instead of writing six hexadecimal characters, you can write only three whenever each pair of characters is identical. Browsers automatically expand the shorthand value, so the displayed color remains exactly the same.

Although this format doesn’t work for every color, it is still useful for common shades such as white, black, gray, red, green, and blue. Understanding when a color can be shortened—and when it can’t—helps you write cleaner HTML and CSS while avoiding invalid color values.

If you frequently work with web colors, an online color picker or HEX converter can quickly tell you whether a six-digit HEX color can be converted into a valid three-digit shorthand. Knowing this small but useful feature will make your CSS easier to read and help you work more efficiently with HTML color codes.

Share:XFacebook

Related Articles