Colors & Backgrounds in CSS

From the CSS cheat sheet ยท Colors & Backgrounds ยท verified Jul 2026

Colors & Backgrounds

Color formats, opacity, gradients, and background sizing

css
/* Color formats */
color: #ff6600;
color: rgb(255, 102, 0);
color: hsl(24, 100%, 50%);
color: oklch(70% 0.2 45);

/* Background */
background: linear-gradient(to right, #3b82f6, #8b5cf6);
background-image: url("bg.jpg");
background-size: cover;
๐Ÿ’ก oklch() produces perceptually even colors โ€” better for design systems than hsl
โšก Use rgb(0 0 0 / 50%) for transparent backgrounds โ€” doesn't affect child elements like opacity does
๐Ÿ“Œ background-size: cover fills the element; contain fits the whole image inside
๐ŸŸข Layer a dark gradient over an image for readable text on photo backgrounds
colorsbackgroundsgradients

More CSS tasks

Back to the full CSS cheat sheet