Skip to main content
AllDevToolsHub
Back to all patterns

CSS rgba() Color

Web & Network

Validates a CSS rgba(r, g, b, a) color string.

/^rgba\(\s*(?:\d{1,3})\s*,\s*(?:\d{1,3})\s*,\s*(?:\d{1,3})\s*,\s*(?:0|1|0?\.\d+)\s*\)$/

How it works

Channels are 0–255 (loosely, this pattern accepts up to 3 digits but does not bound numerically). Alpha is 0–1 with an optional decimal. Modern CSS also allows space-separated rgba(r g b / a) which this regex does NOT match.

Test Cases

Should Match

  • rgba(255, 255, 255, 1)
  • rgba(0,0,0,0.5)
  • rgba(128, 64, 32, .75)

Should NOT Match

  • rgba(255, 255, 255)
  • rgb(255, 255, 255)
  • rgba(255 255 255 / 1)

Quick Summary

Matches the comma-separated rgba(r, g, b, a) CSS syntax.