← Back to functions

CSS Function

rgb()

Color

Defines a color using red, green, blue, and optional alpha (transparency).

Syntax

rgb(r g b) or rgb(r g b / a)

Example

color: rgb(61 255 160); background: rgb(0 0 0 / 0.5);

Common use cases

  • Precise color control
  • Creating overlays with transparency
  • Accessible color mixing

Practical developer insight

Modern CSS supports rgb(r g b / a) syntax without commas — more readable and consistent with hsl(). The old rgba() comma syntax still works but is considered legacy.

Related