.*RegexQuick

Hex Color Regex

Regex for matching CSS hex color codes: #FFF, #FFFFFF, and #FFFFFF80 formats.

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$
//
0 matches

About this pattern

This regex matches CSS hex color codes in all valid formats: 3-digit shorthand (#FFF), 6-digit standard (#FFFFFF), and 8-digit with alpha channel (#FFFFFF80). The pattern requires the # prefix and accepts both uppercase and lowercase hex digits. The alternation is ordered from most specific to least to ensure correct matching.

FAQ

Does this match colors like rgb() or hsl()?

No, this only matches hex color notation (#-prefixed). RGB, HSL, and named colors require different patterns.

More patterns