Lesson 2 · Unit 02
Layout, paint, composite
What each stage works out, and which CSS change makes which stages run again
What you practise
- Geometry, then pixels, then layers
- Which CSS change reruns which stage
Try a question from this lesson
Pick one
A page is one column of 20 paragraphs. A script makes the first paragraph 30px taller. What does the browser have to work out again?
Correct answer
The position of everything below it too
Why
Boxes depend on each other: 19 paragraphs each sit 30px lower, and the page is longer. Working out sizes and positions is called layout, and one small change can ripple through all of it.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Five stages
Every frame comes out of the same five stages, always in this order.
A change does not always need all of them. A new width needs layout and everything after it. A new colour skips layout and goes on to paint. The less a change touches, the cheaper the frame.
parse HTML and CSS into trees
style which rules hit which node
layout size and position of boxes
paint pixels, layer by layer
composite layers stacked on screenConcept
Layers
Paint does not draw the page as one picture. It draws layers, and the compositor stacks them into the frame.
Moving or fading a whole layer needs no new pixels, only a new stacking. That is why transform and opacity are cheap to animate: on an element with its own layer they skip layout and paint.
10 more exercises in the app
- 1× order the lines
- 3× multiple choice
- 3× type the answer
- 1× match the pairs
- 1× true or false
- 1× fill the blanks
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.