What causes a reflow, and why is it expensive?
A reflow is the browser working out the position and the size of every element on the page again. It is expensive because the layout of a page depends on all of its parts. If you change the width of one element, the browser may have to work out new positions for its siblings, for its children, and for everything that comes after it in the flow.
The usual triggers are changes that affect geometry. Setting a width, a height, a margin, a padding, a border, or a font size can all force a reflow. Changing the display property between block and flex does the same thing, and so does adding an element to the page or removing one from it. The browser also reflows when the content changes in a way that alters the size, such as when a web font finishes loading and replaces a fallback font with different measurements.
The part that surprises people is that a reflow can be triggered by reading, and not only by writing. Asking for a layout property such as offsetHeight, offsetWidth, scrollTop, or the result of getBoundingClientRect() forces the browser to finish any pending style and layout work and to compute the answer right now. If that read happens in the middle of a batch of writes, the browser has to do the work twice, once for the writes and again for the read.
That repeated flush is called layout thrashing, and it is the most common cause of a slow page in hand-written interface code. The next answer shows how to avoid it.