The origin is the point where a coordinate system’s reference axes intersect. In two dimensions, it is typically written as (0, 0), and every other point is measured from it. section 1.4.9
For web interfaces, the viewport origin sits at the browser window’s top-left corner. The x-coordinate increases to the right, the y-coordinate increases downward, and pixels are the default unit. section 1.4.9 section 10.1
Reading a pointer position
When the pointer is 120 pixels right and 80 pixels below the viewport’s top-left corner, its viewport coordinates are (120, 80). A mousemove handler exposes those values through e.clientX and e.clientY. section 1.4.9
Use the origin as the reference point for common interface calculations:
- Measure an element’s position with getBoundingClientRect(); its returned edges are relative to the viewport origin. section 1.4.9
- Represent movement as coordinate offsets: adding [50, 20] moves a point 50 pixels right and 20 pixels down. section 10.1
- Allow negative coordinates to place an element partly or entirely above or left of the viewport. section 1.4.9
Table 1.9 Some uses of coordinate systems in CSS and JavaScript
Compare how the viewport origin supports element measurement, pointer tracking, and responsive CSS sizing. section 1.4.9
