• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

The render tree has elements with styles, but the browser doesn’t yet know where to put them on the screen. Without layout calculation, everything would overlap at position (0,0).

Core Idea

Layout (also called reflow) calculates the exact position (x,y) and size (width, height) of each element in the render tree. It runs the CSS box model algorithm to determine where pixels go.

How It Works

  1. Start at root: Begin with <html> element
  2. Box model: Calculate width, height, padding, border, margin per element
  3. Flow: Block elements stack vertically, inline elements flow horizontally
  4. Positioning: Apply position, float, flexbox, grid rules
  5. Output: Each element gets (x, y, width, height)
Element: <div>
- x: 100px, y: 50px
- width: 500px, height: 200px

Visual Explanation

G RenderTree Render Tree Layout Layout Phase Calculate positions/sizes RenderTree->Layout Output Each element: (x, y, w, h) Layout->Output

Key Properties

  • Also called “reflow” when triggered again after initial layout
  • Runs the CSS box model algorithm
  • Parent elements affect children (containing blocks)
  • Expensive operation—avoid forced synchronous layout

Connections

Edge Cases & Gotchas

  • Reading offsetWidth/Height triggers synchronous layout (slow!)
  • display: nonedisplay: block triggers full reflow
  • Animations with top/left cause continuous reflow (use transform instead)
  • Table layout is especially expensive