How do CSS-only background patterns work?
They use repeating gradients (linear, radial, or conic) with hard color stops to draw geometric shapes that tile seamlessly. For example, `repeating-linear-gradient(45deg, #eee 0 10px, #fff 10px 20px)` produces diagonal stripes. Combine multiple gradients with comma-separated `background-image` values to layer dots over stripes or grids over checkerboards. No images needed, infinitely scalable, and tiny in CSS bytes.
When should I use CSS patterns vs an SVG or PNG?
CSS gradient patterns are perfect for simple, geometric repeats like stripes, dots, grids, and checkerboards. They're resolution-independent and recolor instantly with custom properties. Use SVG when the pattern includes curves, complex shapes, or non-geometric details. Reserve raster images for photographic textures (paper, fabric) where gradients can't replicate the organic noise convincingly.
Can I make patterns responsive?
Yes. Use percentages or viewport units for `background-size` to scale the tile with the container, or use CSS variables that you swap via media queries to change pattern density on different viewports. Patterns built from radial gradients accept percentage-based color stop positions that automatically rescale. Avoid hardcoded pixel sizes if you want the pattern to feel consistent across phone, tablet, and desktop layouts.
How do I overlay a pattern on a colored background?
Stack the pattern as `background-image` and a solid color as `background-color`; the pattern renders on top of the color. For multiple pattern layers, list them comma-separated in `background-image` from top-most to bottom-most. The bottom-most layer should be the base color or a fully opaque pattern. Use rgba colors with alpha so underlying layers show through where the pattern is "transparent".
Why does my pattern look different at different sizes?
If you set `background-size` smaller than the gradient's natural repeat unit, the pattern can shift or appear cropped. Make sure the gradient stops align with the tile size. For repeating-gradients, the repeat distance equals the largest hard stop; if `background-size` is smaller, you get a cut-off pattern. Set `background-size` equal to or larger than the repeat unit, then tile naturally.
Can patterns animate?
Yes, by animating `background-position` to slide the pattern across the element. This creates marquee, conveyor-belt, or barber-pole effects without JavaScript. Wrap the animation in `@media (prefers-reduced-motion: no-preference)` since constantly moving backgrounds can be distracting or trigger motion sickness. Animating `background-position` is GPU-accelerated in modern browsers and stays smooth even on long, repeating backgrounds.