Hex Color Code
3 or 6 digit hex color codes
Live Tester— test the Hex Color Code pattern
Pattern
/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/Should match →
Should not match →
Pattern
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$Matching examples
#ff0000#FFFabc123Non-matching examples
#gg0000#12345Breakdown
- #?
- Optional #
- [a-fA-F0-9]{6}
- 6-digit hex
- |[a-fA-F0-9]{3}
- Or 3-digit shorthand