Color formats, gradients, filters, and color manipulation
Standard color names
color: red; background: blue;
Extended color palette
color: darkseagreen; background: lightcoral;
System-defined colors
color: ButtonText; background: Canvas;
Short hex notation
color: #f00; /* red */
Full hex notation
color: #ff0000; /* red */
Hex with alpha channel
color: #ff000080; /* red with 50% opacity */
Red, Green, Blue values
color: rgb(255, 0, 0); /* red */
RGB with alpha channel
color: rgba(255, 0, 0, 0.5); /* red with 50% opacity */
RGB using percentages
color: rgb(100%, 0%, 0%); /* red */
Hue, Saturation, Lightness
color: hsl(0, 100%, 50%); /* red */
HSL with alpha channel
color: hsla(0, 100%, 50%, 0.5); /* red with 50% opacity */
Hue in degrees (0-360)
color: hsl(120deg, 100%, 50%); /* green */
Hue, Whiteness, Blackness
color: hwb(0 0% 0%); /* red */
Lightness, a-axis, b-axis
color: lab(50% 50 50);
Lightness, Chroma, Hue
color: lch(50% 50 50);
Oklab Lightness, Chroma, Hue
color: oklch(50% 0.2 50);
Simple linear gradient
background: linear-gradient(red, blue);
Gradient with direction
background: linear-gradient(to right, red, blue);
Gradient with angle
background: linear-gradient(45deg, red, blue);
Gradient with multiple stops
background: linear-gradient(red, yellow, green);
Gradient with specific stops
background: linear-gradient(red 0%, blue 100%);
Simple radial gradient
background: radial-gradient(red, blue);
Circular radial gradient
background: radial-gradient(circle, red, blue);
Elliptical radial gradient
background: radial-gradient(ellipse, red, blue);
Radial gradient with position
background: radial-gradient(circle at center, red, blue);
Simple conic gradient
background: conic-gradient(red, blue);
Conic gradient with start angle
background: conic-gradient(from 45deg, red, blue);
Conic gradient with center position
background: conic-gradient(from 45deg at 50% 50%, red, blue);
Adjust brightness
filter: brightness(150%);
Adjust contrast
filter: contrast(200%);
Adjust saturation
filter: saturate(50%);
Rotate hue
filter: hue-rotate(90deg);
Invert colors
filter: invert(100%);
Convert to grayscale
filter: grayscale(100%);
Apply sepia effect
filter: sepia(50%);
Blend with background
mix-blend-mode: multiply;
Blend background layers
background-blend-mode: overlay;
Create stacking context
isolation: isolate;
Using CSS custom properties for colors
:root {
--primary-color: #007bff;
--secondary-color: #6c757d;
--success-color: #28a745;
--danger-color: #dc3545;
--warning-color: #ffc107;
--info-color: #17a2b8;
--light-color: #f8f9fa;
--dark-color: #343a40;
}
.button {
background-color: var(--primary-color);
color: white;
}
.button:hover {
background-color: color-mix(in srgb, var(--primary-color) 80%, black);
}
Implementing dark mode with CSS
/* Light mode (default) */
:root {
--bg-color: #ffffff;
--text-color: #333333;
--border-color: #e0e0e0;
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1a1a1a;
--text-color: #ffffff;
--border-color: #404040;
}
}
body {
background-color: var(--bg-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}
Creating gradient text with background-clip
.gradient-text {
background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1);
background-size: 200% 200%;
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
animation: gradient-shift 3s ease infinite;
}
@keyframes gradient-shift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
CSS for generating color palettes
.color-palette {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 1rem;
}
.color-swatch {
aspect-ratio: 1;
border-radius: 8px;
border: 2px solid #e0e0e0;
}
.color-swatch:nth-child(1) { background-color: hsl(0, 100%, 50%); }
.color-swatch:nth-child(2) { background-color: hsl(60, 100%, 50%); }
.color-swatch:nth-child(3) { background-color: hsl(120, 100%, 50%); }
.color-swatch:nth-child(4) { background-color: hsl(180, 100%, 50%); }
.color-swatch:nth-child(5) { background-color: hsl(240, 100%, 50%); }
Use CSS custom properties for consistent color theming
Consider color contrast for accessibility (WCAG guidelines)
Use HSL for easier color manipulation and adjustments
Test colors in both light and dark modes
Use color-mix()
for dynamic color variations