CSS Color Formats
CSS supports several ways to write colors, and modern CSS has added new syntaxes and color spaces. This guide summarizes the formats you are most likely to use and how they differ.
HEX and HEX with alpha
HEX codes are the most common format. Six digits set red, green, and blue; an optional seventh and eighth digit set alpha. Short three- and four-digit forms are shorthand where each digit is doubled.
rgb() and hsl()
Both functions accept a modern space-separated syntax with an optional slash for alpha, for example rgb(255 0 0 / 0.5). The older comma syntax still works everywhere. Percentages are allowed for channels.
hwb() and beyond
hwb() describes a color as hue with added whiteness and blackness, which some designers find intuitive. Newer color functions such as lab() and oklch() offer wider gamuts and more perceptually uniform adjustments; use them with fallbacks where browser support matters.