🎨 Reflow vs Repaint: What Every Frontend Developer Should Know

As front-end developers, understanding how browsers render pages can significantly improve your app’s performance. Two key processes in the rendering pipeline are reflow and repaint. Let’s break down what each does, why they matter, and how you can optimize them.


🧩 What Is Reflow?
  • Also known as layout.
  • Happens when the browser recalculates the positions and sizes of elements on the page.
  • Triggered by changes to element geometry β€” such as CSS properties like width, height, margin, padding, border, or DOM changes.
  • Typically expensive, because it can affect the entire document tree β€” definitely not something you want happening frequently during user interactions.

🎨 What Is Repaint?
  • Also called paint or render.
  • Occurs when visual aspects of elements change β€” like background color, visibility, text color, or shadows.
  • Doesn’t require layout recalculation.
  • Still costs CPU cycles, but is cheaper than reflow.

🏁 Reflow vs Repaint: A Quick Comparison
FeatureReflow (Layout)Repaint (Rendering)
Trigger exampleswidth, height, padding, margin, border, DOM structure changesbackground-color, color, visibility, outline
What is updatedElement geometry & layoutElement pixels/color
Browser workFull re-computation of layout treeJust re-drawing visuals
Performance impactHigh (can cascade through DOM)Moderate (confined to affected elements)

⚑ Performance Optimization Techniques

Here are three actionable ways to reduce reflow and repaint overhead:

  1. Minimize layout-triggering CSS changes
    Avoid changing geometry-related properties (e.g., width, margin) frequently, especially during animations. Set them upfront in CSS when possible.
  2. Use GPU-accelerated properties for animations
    Stick to transform and opacity β€” both can be handled by the GPU, avoiding layout recalculation. This yields smoother animations.
  3. Use will-change mindfully
    Hint that an element will change (e.g., will-change: transform) so the browser can prepare optimizations. But use sparingly β€” overuse can increase memory usage.

🧩 Real-World Example: Click-to-Expand Card

Imagine a card that expands on click.

Bad (triggers reflow):

Better (GPU-accelerated repaint only):

Or hint it in advance:

This ensures only a repaint, not a layout shift β€” resulting in smoother UI updates.


βœ… TL;DR
  • Reflow recalculates layout and positions β€” expensive!
  • Repaint redraws visuals β€” less costly, but still avoidable.
  • Use transform & opacity with GPU acceleration for animations.
  • Use will-change strategically to help browsers optimize.

✨ Final Thoughts

Smooth, responsive UI isn’t just about clean code β€” it’s about knowing how browsers work under the hood. Minimizing reflow and repaint not only improves performance but makes your interface feel faster and more pleasant.

If you’d like, I can help convert this into a developer-friendly Markdown guide or include real-world performance metrics. Just let me know!

Kuni
Kuni

Hi, I’m a developer based in South Korea. With years of experience in the tech industry, I am passionate about creating meaningful solutions and continually learning in this ever-evolving field.

I believe in the importance of leading a healthy and balanced economic life, and I aim to share insights, ideas, and practical tips to help others achieve the same. Through this blog, I hope to connect with like-minded individuals, exchange valuable knowledge, and grow together.

Let’s explore, learn, and build a thriving life together!

Let me know if you'd like further adjustments! 😊

Leave a Reply