getBoundingClientRect: Measuring Elements

Measure Rara’s box in a real page on the teacher’s board: whose numbers change when the page scrolls or the box turns, pixel fractions, the width reported…

Why it matters

Tooltips, dropdowns, popovers and highlights beside an element need its place on screen, and that is getBoundingClientRect()’s job: libraries like Floating UI are built on it. Mistaking the rect for document coordinates makes a popover miss as soon as the page scrolls.

The key idea

The rect is viewport-relative, and measures what is drawn

Common mistakes

Try it in this playground