GPU Acceleration in CSS: What It Can and Can't Do
In this article
GPU acceleration in CSS lets the browser offload certain visual tasks—like animations, transforms, and compositing—to your graphics card instead of the CPU. The result is smoother motion, fewer dropped frames, and better performance on complex pages. To use it, you don't need any special software; you just write CSS properties that trigger the GPU's compositing pipeline. But there are limits: CSS can't guarantee that every animation will run at 60fps, and it can't force the GPU to be used if the browser decides otherwise. Here's how to make the most of it and what to watch out for.
What You'll Need
- A modern browser (Chrome, Firefox, Safari, Edge) with hardware acceleration enabled (it's on by default in most).
- A computer with a GPU that supports hardware acceleration—most integrated and dedicated GPUs do.
- Basic knowledge of CSS properties like
transform,opacity, andanimation. - A code editor and a browser's developer tools (to inspect performance).
Step-by-Step
- Use GPU-friendly properties. Stick to
transform(translate, scale, rotate) andopacityfor animations. These are composited on the GPU. Avoid animatingwidth,height,top, orleft—those trigger layout and paint on the CPU. - Add
will-changeto hint the browser. For elements you plan to animate, addwill-change: transformorwill-change: opacitybefore the animation starts. This tells the browser to prepare a layer for that element. Don't overuse it—too many layers can eat memory. - Use
translateinstead oftop/left. To move an element, usetransform: translateX(100px)rather thanleft: 100px. The transform runs on the GPU; the positional property triggers layout. - Animate with
requestAnimationFramefor JavaScript-driven animations. If you're using JS to animate, pair it with CSS transforms (e.g., updatingtransformin the rAF callback) to keep everything on the compositor thread. - Check the browser's compositor layers. In Chrome DevTools, open the Rendering tab and enable "Layer borders" or "Paint flashing". You'll see which elements are on their own layer (GPU-accelerated) and which are being repainted.
- Test performance with FPS meter. In DevTools, open the Performance panel, record a few seconds of your animation, and look for frame drops. Aim for a steady 60 frames per second.
- Use
contain: layout paint(optional). This CSS property tells the browser that an element's layout and paint are independent, which can help isolate GPU layers and reduce repaint scope.
Common Mistakes
- Animating non-GPU properties. Changing
margin,padding, orbox-shadowforces layout/paint on every frame—the GPU can't help. - Overusing
will-change. Applying it to dozens of elements creates many layers, consuming GPU memory and actually slowing things down. - Forgetting to promote layers early. If you add
will-changeright when the animation starts, the browser has to create the layer mid-animation, causing a janky start. - Assuming GPU acceleration is always faster. For simple, short animations, the overhead of creating a layer can be worse than just letting the CPU handle it.
Tips
- Combine multiple transforms in one
transformdeclaration, e.g.,transform: translateX(10px) scale(1.1), to avoid multiple layer updates. - Keep animated elements small in size; large layers use more GPU memory and can be slower.
- Use the
translateproperty (separate fromtransform) in modern browsers for even better performance—it's now a standalone property. - Test on real devices, especially low-end phones, to see if GPU acceleration actually helps or hurts.
Troubleshooting
Animation is still janky. Open DevTools Performance and check if frames are being dropped. If you see long "Layout" or "Paint" tasks, you're likely animating a property that triggers those. Switch to transform and opacity.
Elements flicker or disappear. This can happen when a layer is created and destroyed rapidly. Try adding will-change persistently, or use translate instead of transform to avoid re-compositing.
GPU memory is maxed out. If you have too many layers, the browser may start rasterizing on the CPU. Reduce the number of elements with will-change and avoid huge fixed-position layers.
Nothing seems GPU-accelerated. Check if hardware acceleration is disabled in your browser settings. In Chrome, go to Settings > System and ensure "Use hardware acceleration when available" is on. Also, some corporate-managed browsers disable it.
Frequently Asked Questions
Does GPU acceleration work in all browsers?
No. While all modern browsers support compositing, the exact properties that get GPU-accelerated can vary. For example, Safari historically had issues with will-change. Always test in the browsers your users actually use.
Can I force the GPU to be used?
No. CSS cannot force the browser to use the GPU. The browser decides based on the properties you use and its own heuristics. You can only hint via will-change and by using compositable properties.
Does transform: translateZ(0) still help?
It used to be a common trick to force a layer, but modern browsers handle this automatically. It's not harmful, but it's unnecessary and can create extra layers if overused.
Why is my animation slow even with transforms?
It could be because the element is very large, or there are too many layers, or the GPU is weak. Also, if the element has a complex box-shadow or backdrop-filter, those are expensive to composite.
Can I use GPU acceleration for static pages?
Not really—GPU acceleration is only relevant during compositing (e.g., scrolling, animations, transitions). For static content, there's nothing to accelerate.
Is there a downside to GPU acceleration?
Yes. It uses GPU memory, which is limited. Too many layers can cause crashes or slowdowns on low-end devices. Also, moving data between CPU and GPU has a cost, so for trivial animations it's not worth it.