Course contentsShow
← Web Development
Lesson 24 of 2,9821. The Web Platform FoundationFree lesson

Layout and Reflow

How browsers calculate the position and size of elements on the page.

Layout and Reflow

You'll learn how browsers transform the Render Tree into actual pixel positions on your screen.

Once the browser has constructed the Render Tree (combining the DOM and CSSOM), it knows what to display—but not yet where or how big each element should be. That's where layout comes in.

What is Layout?

Layout (sometimes called "reflow") is the process where the browser calculates the exact position and size of every element on the page. Think of it like arranging furniture in a room: you know what pieces you have (the Render Tree), but now you need to figure out where each piece goes and how much space it takes up.

The browser starts at the top of the Render Tree and works its way down, calculating:

  • Width and height of each box
  • Position relative to the viewport and other elements
  • Margins, padding, and borders

The Box Model in Action

Remember, every HTML element is a box. During layout, the browser computes the dimensions of each box based on CSS rules. A <div> might be 300 pixels wide because you set width: 300px, or it might stretch to fill its parent container by default.

What is Reflow?

Reflow happens when the layout needs to be recalculated. This occurs when:

  • The page first loads
  • The browser window is resized
  • Content changes (text added/removed)
  • CSS properties affecting size or position change

Reflow can be expensive because the browser may need to recalculate many or all elements, not just the one that changed.

Key takeaway: Layout is the browser's geometry calculation phase—it figures out where every box goes and how big it is before painting pixels to the screen.