| 1 | --- |
| 2 | title: Animate SVG Wrapper Instead of SVG Element |
| 3 | impact: LOW |
| 4 | impactDescription: enables hardware acceleration |
| 5 | tags: rendering, svg, css, animation, performance |
| 6 | --- |
| 7 | |
| 8 | ## Animate SVG Wrapper Instead of SVG Element |
| 9 | |
| 10 | Many browsers don't have hardware acceleration for CSS3 animations on SVG elements. Wrap SVG in a `<div>` and animate the wrapper instead. |
| 11 | |
| 12 | **Incorrect (animating SVG directly - no hardware acceleration):** |
| 13 | |
| 14 | ```tsx |
| 15 | function LoadingSpinner() { |
| 16 | return ( |
| 17 | <svg className=" |
| 18 | <circle cx=" |
| 19 | </svg> |
| 20 | ); |
| 21 | } |
| 22 | ``` |
| 23 | |
| 24 | **Correct (animating wrapper div - hardware accelerated):** |
| 25 | |
| 26 | ```tsx |
| 27 | function LoadingSpinner() { |
| 28 | return ( |
| 29 | <div className=" |
| 30 | <svg width=" |
| 31 | <circle cx=" |
| 32 | </svg> |
| 33 | </div> |
| 34 | ); |
| 35 | } |
| 36 | ``` |
| 37 | |
| 38 | This applies to all CSS transforms and transitions (`transform`, `opacity`, ` |