LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. Animation performance

Layout thrashing

Also called forced synchronous layout or forced reflow

A slowdown caused by code that alternates style changes with size reads, forcing the browser to recalculate layout many times in one frame.

import { useLayoutEffect, useRef } from 'react';

type Plan = { name: string; features: string[] };

export function PlanCards({ plans }: { plans: Plan[] }) {
  const listRef = useRef<HTMLUListElement>(null);

  useLayoutEffect(() => {
    const cards = Array.from(listRef.current?.children ?? []) as HTMLElement[];
    for (const card of cards) card.style.height = '';
    // Read every height in one pass, so one layout answers them all...
    const tallest = Math.max(...cards.map((card) => card.offsetHeight));
    // ...then write every height. Reading offsetHeight between writes
    // would force a fresh layout for every card.
    for (const card of cards) card.style.height = `${tallest}px`;
  }, [plans]);

  // Where you can, let CSS do it with no measuring: a grid with auto-rows-fr.
  return (
    <ul ref={listRef} className='flex flex-wrap items-start gap-4'>
      {plans.map((plan) => (
        <li
          key={plan.name}
          className='w-60 rounded-xl border bg-background p-5'
        >
          <h3 className='font-semibold'>{plan.name}</h3>
          <ul className='mt-2 space-y-1 text-sm text-muted-foreground'>
            {plan.features.map((feature) => (
              <li key={feature}>{feature}</li>
            ))}
          </ul>
        </li>
      ))}
    </ul>
  );
}
Fix layout thrashing in the function that equalizes card heights: read every card's offsetHeight in one loop first, then set all the heights in a second loop, and run it inside requestAnimationFrame. Where possible, replace the manual measuring with CSS Grid or a ResizeObserver.

Paste into Layerwise or any AI coding tool.

What is Layout thrashing?

Normally the browser collects your style changes and recalculates layout once per frame. Reading a layout value such as offsetHeight, offsetWidth, or getBoundingClientRect() right after a change forces it to lay out the page immediately so the answer is correct. Do that in a loop, changing then measuring element after element, and the browser redoes layout on every pass.

It often hides in code that sizes a list of elements, matches card heights, or measures things on every scroll event. In the Chrome DevTools Performance panel it shows up as a run of purple Layout blocks with a forced reflow warning.

The fix is to batch: read every measurement first, then make every change. ResizeObserver reports sizes without forcing extra layouts, and CSS Grid or Flexbox can often replace the measuring entirely. For motion, animating width, height, top, or left makes the browser lay out again on every frame, while transform and opacity usually skip layout.

Often confused with

Jank
Jank is the stutter you see. Layout thrashing is one common cause of it.

Related terms

All terms

Jank

Visible stutter in an animation or scroll, caused when the browser misses frames because it cannot finish its work in time.

GPU acceleration

A browser technique where the graphics chip moves, fades, or scales an element on its own layer instead of redrawing the page every frame.

Frame rate (FPS)

The number of frames a screen draws each second; around 60 fps, motion looks smooth, and at lower rates it starts to look choppy.

Debounce

A technique that waits for a short pause in typing or other repeated events, then runs the work once instead of on every keystroke.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit

Read, write, repeat

Missed frame

6 layouts · 20.0 ms

Read all, then write

On time

1 layout · 9.0 ms

  • Script
  • Layout
  • Paint
  • Composite
  • 16.7 ms budget