Expand CSS hex shorthand
CSS lets you write a hex color in a compact 3-digit form, where #F80 is exactly the same color as #FF8800. This tool expands that shorthand — and the 4-digit alpha variant #RGBA — into the full canonical form by doubling each digit, validates the input, and previews the result with a live swatch. It is the quick way to normalize colors before storing or comparing them.
How it works
Expansion is a simple per-digit doubling: every single hex digit is repeated to form a byte. So #F80 expands as F to FF, 8 to 88, 0 to 00, giving #FF8800. The same rule applies to the 4-digit alpha shorthand, where the fourth digit becomes the alpha byte: #F80a becomes #FF8800AA. The tool first strips an optional leading hash, checks that the body is valid hex and a legal length (3, 4, 6, or 8), then either expands the short forms or passes the already-full forms through unchanged.
A table of representative expansions
| Shorthand | Expanded | What you see |
|---|---|---|
#000 | #000000 | Black |
#fff | #ffffff | White |
#f00 | #ff0000 | Pure red |
#0f0 | #00ff00 | Pure green |
#00f | #0000ff | Pure blue |
#abc | #aabbcc | Slate blue-grey |
#F80 | #FF8800 | Orange |
#0f08 | #00ff0088 | Semi-transparent green |
Notice that shorthand can only represent 16 steps per channel (0, 1, 2 … up to F),
which is why only a limited subset of colors can be expressed in three digits.
Any color whose channels do not divide evenly into “digit doubled” values — for
example #3b82f6 (a popular blue) — has no valid shorthand form.
Why the rule is doubling, not padding
A common mistake is to assume #F80 expands to #F08000 (padding with zeros).
That would be wrong — it would change the color. The CSS specification defines
shorthand as “doubling each digit” because that preserves proportionality.
For the red channel:
Fin hex = 15 in decimal, which is the maximum single digitFFin hex = 255 in decimal, which is the maximum byte
Doubling F to FF maps the maximum single-digit value to the maximum byte
value. Padding with zero would give F0 = 240 in decimal — a lighter red, not
the intended maximum red.
The doubling rule: digit × 16 + digit = digit × 17. So A (10 decimal)
becomes AA = 10 × 17 = 170. 5 becomes 55 = 5 × 17 = 85.
When this tool is useful
- CSS refactoring: You have a codebase mixing shorthand and full-form hex and want to normalize everything to 6-digit before passing to a color parser.
- Comparing colors: Two hex values can look different in string form but be
the same color (
#fffand#ffffff). Expanding both before comparison catches this. - Design token pipelines: Build tooling that processes design tokens often requires consistent 6- or 8-digit hex input; running shorthand through this expander cleans the input automatically.
- Quick validation: The tool validates whether a hex string is legal CSS before you attempt to use it in code, flagging bad lengths or non-hex characters immediately.
#abc expands to #aabbcc, and #0f08 expands to #00ff0088. Everything
runs in your browser — no data is sent anywhere.