Animation performance
Definition and purpose
Motion can change layout, paint, or composition work. Prefer a transform for decorative displacement when siblings do not need to reflow, but measure rather than assuming a guaranteed fast path.
Change layout width
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } .row { display: flex; } #a { width: 160px; } #b { width: 60px; } </style> </head> <body> <div class="row"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>B starts at 160px because A reserves that width.
Syntax and mental model
Width changes can affect neighboring geometry; transform modifies the visual result after normal sizing. Opacity and transform are common candidates for compositing, but layer promotion depends on the engine and scene. will-change is a hint with potential memory and stacking side effects, not an instruction to allocate a GPU layer. Compare frame timing and layout/paint records in a profiler before and after a change.
Translate without reflow
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } .row { display: flex; } #a { width: 100px; transform: translateX(40px); } #b { width: 60px; } </style> </head> <body> <div class="row"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>A moves visually; B stays at its original layout position.
Common mistakes
A transformed rectangle may overlap a neighbor; if the design needs space to grow, layout changes can be the correct choice. Do not apply will-change globally.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: View transitions. Next lesson: Reset and normalization.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Animation performance — knowledge check
Five questions on animation performance.
Which property can move a box without changing normal flow space?
Does transform guarantee GPU acceleration?
What does will-change provide?
When is width animation appropriate?
How should you evaluate performance?