liveBook · Manning

Horizontal axis

As explained in Math for Web Design

The x-axis is the horizontal reference axis in a two-dimensional coordinate system.

The horizontal axis, usually called the x-axis, is the left-to-right reference line for locating points in a two-dimensional coordinate system. In a browser viewport, its origin is at the top-left corner, positive x values extend rightward, and pixels are the usual unit. section 1.4.9

Use the horizontal axis to reason about:

  • CSS positioning and DOM measurements, where an element's horizontal position is measured from the viewport origin. section 1.4.9
  • Mouse interaction, where event.clientX reports the pointer's horizontal viewport coordinate. section 1.4.9 section 13.4
  • Motion and angles, where 0° points right along the positive x-axis and angles increase clockwise because screen y values increase downward. section 10.1

Converting a movement into horizontal and vertical parts

A 100px movement at 30° from horizontal has an x component of 86.6px and a y component of 50px. JavaScript or CSS can calculate those components with cosine and sine. section 10.1

x = length * Math.cos(θ)
y = length * Math.sin(θ)

Calculate the horizontal and vertical components of a movement from its length and angle. section 10.1

How Math for Web Design covers it

How deep it goes
Defines the axis and viewport direction, then connects it to vector angles and trigonometric components.
Examples
Uses viewport positioning, mouse coordinates, element bounds, and a 100px movement at 30°.
What it assumes
Assumes familiarity with two-dimensional points and coordinates while establishing viewport directions from the origin.
What you can do after
Apply it via CSS and JavaScript to interpret horizontal positions, pointer coordinates, and directional movement.
How it connects
Connects coordinate systems, the y-axis, the origin, viewport coordinates, vectors, and angles.

Also explained in

Compare how 2 books explain horizontal axis →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.